home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ibmtool.zip
/
msg.c
< prev
next >
Wrap
Text File
|
1997-11-07
|
9KB
|
292 lines
/******************************************************************************/
/* */
/* FILE: MSG.C */
/* */
/* PURPOSE: This file contains the Message window code. */
/* */
/* FUNCTIONS: InitMsg */
/* PrintMsg */
/* hexprint */
/* DoMessageWindow */
/* */
/* GLOBAL DATA ACCESSED */
/* BOOLEAN HelpMode */
/* BOOLEAN ScriptMode */
/* BOOLEAN SLog */
/* FILE *ScriptFile */
/* *LogFile */
/* WINDOW Msg */
/* */
/******************************************************************************/
#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 "ioctl.h"
#include "intrface.h"
MESSAGE Message[MAXMSGS];
MESSAGE *MsgTop, *CurrMsg, *MsgHead, *ViewBot;
int MsgCnt = 0;
void InitMsg ()
{
int i;
// initialize the message queue
ViewBot = MsgHead = CurrMsg = MsgTop = &Message[0];
for (i=0; i<MAXMSGS - 1; ++i)
Message[i].next = &Message[i+1];
Message[i].next = &Message[0];
for (i=MAXMSGS - 1; i>0; --i)
Message[i].prev = &Message[i-1];
Message[i].prev = &Message[MAXMSGS - 1];
}
void PrintMsg (BYTE mAttr, char *fmt, ...)
{
BYTE bAttr[2] = " ";
char str[80]; /* Buffer to build sting into */
int i;
va_list argptr; /* Argument list pointer */
MESSAGE *pmsg;
va_start (argptr, fmt); /* Initialize va_ functions */
vsprintf (str, fmt, argptr); /* prints string to buffer */
va_end (argptr); /* Close va_ functions */
if (SLog) fprintf (LogFile, "%s\n", str);
if (ScriptMode)
{
printf ("%s\n", str);
return;
}
strcpy (CurrMsg->Msg, str);
CurrMsg->MsgAttr = (mAttr == 0) ? Msg.Attr : mAttr;
bAttr[1] = Msg.Attr;
if (MsgCnt > Msg.Lines - 1)
{
if (ViewBot->next != CurrMsg)
{
ViewBot = CurrMsg->prev;
MsgTop = ViewBot;
for (i=0; i<Msg.Lines - 1; ++i)
MsgTop = MsgTop->prev;
if (!HelpMode)
{
ClearWindow (Msg);
pmsg = MsgTop;
for (i=0; i<Msg.Lines; ++i)
{
VioWrtCharStrAtt (pmsg->Msg, strlen (pmsg->Msg),
Msg.Top+i, Msg.Left, &pmsg->MsgAttr, 0);
pmsg = pmsg->next;
}
} /* endif */
}
MsgTop = MsgTop->next;
ViewBot = ViewBot->next;
if (MsgTop == MsgHead) MsgHead = MsgHead->next;
if (!HelpMode)
{
VioScrollUp (Msg.Top, Msg.Left, Msg.Bottom, -1, 1, bAttr, 0);
VioWrtCharStrAtt (CurrMsg->Msg, strlen (CurrMsg->Msg),
Msg.Bottom, Msg.Left, &CurrMsg->MsgAttr, 0);
} /* endif */
}
else
{
ViewBot = CurrMsg;
if (!HelpMode)
VioWrtCharStrAtt (CurrMsg->Msg, strlen (CurrMsg->Msg),
Msg.Top + MsgCnt, Msg.Left, &CurrMsg->MsgAttr, 0);
}
CurrMsg = CurrMsg->next;
if (++MsgCnt == MAXMSGS) MsgCnt = MAXMSGS;
}
void hexprint (char far *buffer, int length, BOOLEAN pause)
{
char hexstr[80] = " xxxx ";
char ascstr[30] = " ";
char tstr[5];
char *p = hexstr + 7;
int i, j, linecnt = 0, hexcnt = 0;
KBDKEYINFO KbdInfo;
for (i=1; i<length+1; ++i)
{
sprintf (p, "%02X ", (unsigned char) buffer[i-1]);
if (buffer[i-1] >= 0x20 && buffer[i-1] <= 0x7E)
{
sprintf (tstr, "%c", buffer[i-1]);
strcat (ascstr, tstr);
}
else
strcat (ascstr, "·");
if (i && !(i % 16))
{
strcat (hexstr, ascstr);
sprintf (tstr, "%04X ", hexcnt);
for (j=0; j<4; ++j)
hexstr[j+1] = tstr[j];
hexcnt += 16;
PrintMsg (0, hexstr);
if (++linecnt > Msg.Lines - 2)
{
linecnt = 0;
if (pause && i < length)
{
PrintMsg (0, "---More---");
KbdCharIn (&KbdInfo, IO_WAIT, 0);
} /* endif */
}
strcpy (hexstr, " xxxx ");
strcpy (ascstr, " ");
p = hexstr + 7;
}
else
p += 3;
} /* endfor */
if ((i - 1) % 16)
{
sprintf (tstr, "%04X ", hexcnt);
for (j=0; j<4; ++j)
hexstr[j+1] = tstr[j];
memset (p, ' ', (16 - ((i - 1) % 16)) * 3);
*(p + (16 - ((i - 1) % 16)) * 3) = '\0';
strcat (hexstr, ascstr);
PrintMsg (0, hexstr);
}
}
void DoMessageWindow ()
{
BYTE bAttr[2] = " ";
int i, j, lines;
USHORT row, col;
BOOLEAN done = FALSE;
MESSAGE *pmsg;
KBDKEYINFO kbdInfo;
VIOCURSORINFO CursorInfo;
bAttr[1] = Msg.Attr;
VioSetCurPos (Msg.Top, Msg.Left, 0);
while (!done)
{
KbdCharIn (&kbdInfo, IO_WAIT, 0);
VioGetCurPos (&row, &col, 0);
switch (kbdInfo.chScan)
{
case TAB:
done = TRUE;
break;
case UP:
if (row > Msg.Top)
{
VioSetCurPos (row - 1, col, 0);
break;
}
if (MsgTop != MsgHead)
{
MsgTop = MsgTop->prev;
ViewBot = ViewBot->prev;
VioScrollDn (Msg.Top, Msg.Left, Msg.Bottom, -1, 1, bAttr, 0);
VioWrtCharStrAtt (MsgTop->Msg, strlen (MsgTop->Msg),
Msg.Top, 0, &MsgTop->MsgAttr, 0);
}
break;
case DOWN:
if (row < MAXROW)
{
VioSetCurPos (row + 1, col, 0);
break;
}
if (MsgCnt > Msg.Lines - 1 && ViewBot->next != CurrMsg)
{
MsgTop = MsgTop->next;
ViewBot = ViewBot->next;
VioScrollUp (Msg.Top, Msg.Left, Msg.Bottom, -1, 1, bAttr, 0);
VioWrtCharStrAtt (ViewBot->Msg, strlen (ViewBot->Msg),
Msg.Bottom, 0, &ViewBot->MsgAttr, 0);
}
break;
case PGUP:
if (MsgTop == MsgHead)
{
VioSetCurPos (Msg.Top, Msg.Left, 0);
break;
}
i = 0;
while (MsgTop != MsgHead && i < Msg.Lines)
{
MsgTop = MsgTop->prev;
ViewBot = ViewBot->prev;
++i;
} /* endwhile */
ClearWindow (Msg);
pmsg = MsgTop;
for (i=0; i<Msg.Lines; ++i)
{
VioWrtCharStrAtt (pmsg->Msg, strlen (pmsg->Msg),
Msg.Top+i, Msg.Left, &pmsg->MsgAttr, 0);
pmsg = pmsg->next;
}
break;
case PGDN:
if (MsgCnt < Msg.Lines) break;
if (ViewBot->next == CurrMsg)
{
VioSetCurPos (Msg.Bottom, Msg.Left, 0);
break;
}
i = 0;
while (ViewBot->next != CurrMsg && i < Msg.Lines)
{
ViewBot = ViewBot->next;
MsgTop = MsgTop->next;
++i;
} /* endwhile */
ClearWindow (Msg);
pmsg = MsgTop;
for (i=0; i<Msg.Lines; ++i)
{
VioWrtCharStrAtt (pmsg->Msg, strlen (pmsg->Msg),
Msg.Top+i, Msg.Left, &pmsg->MsgAttr, 0);
pmsg = pmsg->next;
}
break;
} /* endswitch */
} /* endwhile */
}