Mail Archives: djgpp/1999/08/26/02:21:19
From: | "Campbell, Rolf [SKY:1U32:EXCH]" <cp1v45 AT NortelNetworks DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Dosc Log
|
Date: | Wed, 25 Aug 1999 10:36:16 -0400
|
Organization: | Nortel Networks
|
Lines: | 547
|
Message-ID: | <37C3FF60.9AC3B692@NortelNetworks.com>
|
NNTP-Posting-Host: | bmerhc00.ca.nortel.com
|
Mime-Version: | 1.0
|
X-Mailer: | Mozilla 4.7 [en] (X11; I; HP-UX B.10.20 9000/712)
|
X-Accept-Language: | en
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
This is a multi-part message in MIME format.
--------------39487F263D904C57CA8F2F14
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Here's the Dosc Log (si) files and a simple checksum function.
--
-Rolf Campbell (39)3-6318
--------------39487F263D904C57CA8F2F14
Content-Type: text/plain; charset=us-ascii;
name="dosclogim.aa02"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="dosclogim.aa02"
SECTION DOSCLOGIM OF DOSCLOGSI;
/* EDITION AA02 (PEG00), UNXDEV PBEER.50 (99/07/21 21:59:00) -- OPEN */
// Time-stamp: <99/08/25 10:17:27 cp1v45>
#ifdef LOCAL_COMPILE
#include "dosclogsi.aa02"
#include <stdio.h>
unsigned si_RelTime;
#endif
/* Total number of logable messages */
#define PO_LOG_LINES 1000
/* Maximum usable size of each log message */
#define PO_LINE_WIDTH 80
/* Extra size used for timestamp */
#define PO_TIMESTAMP_WIDTH 12
/* The number of rows to display per page when in paging mode */
#define ROWS_IN_PAGE 20
/* The po log buffer. */
typedef struct {
int start;
int count;
char text[PO_LOG_LINES+1][PO_LINE_WIDTH+PO_TIMESTAMP_WIDTH];
/* '+1' so there can be 80 characters then the null */
} PoLogBuffType;
/* This type specifies the destination of a log. */
typedef enum logDestinationType {
toBuffer = 0,
toScreen = 1
#ifdef LOCAL_COMPILE
, toFile = 2
#endif
} LogDestination;
/* This is used to hold whether paging is on or off */
typedef enum {DOSC_OFF, DOSC_ON} OnOffType;
/* Scratch pad area. */
/* '*2' because people might write more than 80 characters. */
/* '+1' so there can be 160 characters and then the null */
char potxt[PO_LINE_WIDTH*2+1];
static PoLogBuffType poLogBuff; /* The actual log */
static OnOffType pageMode; /* Is paging on? */
static LogDestination logDestination; /* Where to write each message */
#ifdef LOCAL_COMPILE
FILE* logFile = NULL; /* The file to be used as a buffer if required */
#endif
/* These are used to hold which applications are blocked from sending
messages */
static int blocked[DOSC_APP_TYPE_SIZE];
/* This is used to remember the old list of blocked apps when
savePoBlockedApps is called */
static int blockedBackup[DOSC_APP_TYPE_SIZE];
#ifdef LOCAL_COMPILE
int main(void)
{
int i, low, high;
dosclogsi_entry();
low=30;
high=40;
for(i=0; i<100; i++) {
if(i==low) blockPoApp(DOSC_LINK);
else if(i==high) unBlockPoApp(DOSC_LINK);
sprintf(potxt, "I am #%d! And I am really long!!! Hi. How are you????????", i);
writePoLog(DOSC_LINK, potxt);
}
turnPoPagingOn();
blockAllPoApps();
if(printPoLogFromOffset(0)==FALSE)
printf("Could not print because some signals are not blocked.\n");
for(;;) {
char* input;
printf("PrintLog" "\t");
printf("PagingOn" "\t");
printf("PagingOff" "\t");
printf("ClearLog" "\t");
printf("SaveApps" "\t");
printf("RestoreApps" "\t");
printf("BlockAll" "\t");
printf("UnBlockAll" "\t");
printf("PrintFromOffset" "\t");
printf("BlockAnApp" "\t");
printf("UnBlockAnApp" "\t");
printf("CurrentLogSize" "\t");
printf("NewestMessages" "\n");
input = MON_get_line();
if(!strcmp(input, "PrintLog")) print_po_log();
if(!strcmp(input, "PagingOn")) turnPoPagingOn();
if(!strcmp(input, "PagingOff")) turnPoPagingOff();
if(!strcmp(input, "ClearLog")) clear_po_log();
if(!strcmp(input, "SaveApps")) savePoBlockedApps();
if(!strcmp(input, "RestoreApps")) restorePoBlockedApps();
if(!strcmp(input, "BlockAll")) blockAllPoApps();
if(!strcmp(input, "UnBlockAll")) unBlockAllPoApps();
if(!strcmp(input, "PrintFromOffset")) printFromOffset_interface();
if(!strcmp(input, "BlockAnApp")) blockAnApp_interface();
if(!strcmp(input, "UnBlockAnApp")) unBlockAnApp_interface();
if(!strcmp(input, "CurrentLogSize")) currentBufferSize_interface();
if(!strcmp(input, "NewestMessages")) printLastMessages_interface();
}
return 0;
}
#endif
/* This function writes a string to the logDestination, if the sending app
has not been blocked. A time-stamp is prepended to the string. If the
buffer is full, then the oldest message is overwritten. */
void writePoLog(AppType app, char *text)
{
if(blocked[app]) return; /* Do nothing if sending app is blocked */
switch (logDestination) {
case toScreen:
/* Just output to the screen */
printf("\n%010d: %s", si_RelTime, text);
break;
case toBuffer:
/* Print the text string into the buffer preceded by the timestamp. */
sprintf(poLogBuff.text[(poLogBuff.start + poLogBuff.count) % PO_LOG_LINES], "%010d: ", si_RelTime);
strncat(poLogBuff.text[(poLogBuff.start + poLogBuff.count) % PO_LOG_LINES], text, 80);
/* Adjust end to the next free position. */
if(poLogBuff.count == PO_LOG_LINES)
poLogBuff.start = (poLogBuff.start+1) % PO_LOG_LINES;
else
poLogBuff.count++;
break;
#ifdef LOCAL_COMPILE
case toFile:
/* Just dump the log into the file. */
fprintf(logFile, "\n%010d: %s", si_RelTime, text);
break;
#endif
default:
break;
}
}
/* Enables displaying one page at a time */
void turnPoPagingOn(void)
{
pageMode = DOSC_ON;
}
/* Disables displaying one page at a time */
void turnPoPagingOff(void)
{
pageMode = DOSC_OFF;
}
/* Prints all of the entries in the buffer, skipping the first 'offset' entries. */
/* If paging is on, then after one page full, printing pauses and the user */
/* is prompted to press enter to display the next page. */
int printPoLogFromOffset(int offset)
{
int i, ret=TRUE;
if(offset>poLogBuff.count) offset=poLogBuff.count;
if(pageMode==DOSC_OFF)
for(i = 0; i<poLogBuff.count-offset; i++)
printf("\n%s", poLogBuff.text[(poLogBuff.start+offset+i) % PO_LOG_LINES]);
else {
if(countUnblockedApps()>0) ret=FALSE;
else {
int numElements=poLogBuff.count-offset,
linesPrinted=0;
for(i=0; i<numElements; i++) {
char* curString = poLogBuff.text[(i+offset+poLogBuff.start)%PO_LOG_LINES];
if(linesPrinted!=0 && (linesPrinted%ROWS_IN_PAGE==0 ||
(linesPrinted%ROWS_IN_PAGE==ROWS_IN_PAGE-1 && strlen(curString)>80))) {
printf("\nPress enter for the next page. 'q' to quit.");
if(tolower(MON_get_line()[0])=='q') {
printf("\n");
return ret;
}
}
printf("\n%s", curString);
linesPrinted += ((strlen(curString)>80) ? 2 : 1);
}
}
}
printf("\n");
return ret;
}
/* This is just for backwards compatability, it prints all entries in the buffer */
/* by calling printPoLogFromOffset. */
int print_po_log(void)
{
return printPoLogFromOffset(0);
}
/* Prints the most recent 'count' messages in the buffer. */
int printLastMessages(int count)
{
if (count>poLogBuff.count) count=poLogBuff.count;
return printPoLogFromOffset(poLogBuff.count-count);
}
/* Clears the contents of the buffer. */
void clear_po_log(void)
{
/* Initialize the po log buffer. */
poLogBuff.start = 0;
poLogBuff.count = 0;
}
/* Causes all logging to be redirected to the screen. */
void logs_to_screen(void)
{
logDestination = toScreen;
}
/* Causes all logging to go into the power optimizer log buffer. */
void logs_to_buffer(void)
{
logDestination = toBuffer;
}
#ifdef LOCAL_COMPILE
/* Causes all loggint to go into a file called 'dosc.log'. */
void logs_to_file(void)
{
fclose(logFile);
if(!(logFile = fopen("dosc.log", "wt")))
printf("Could not open log file.\n");
logDestination = toFile;
}
#endif
/* Disables writes to the buffer from a specific application */
void blockPoApp(AppType app)
{
blocked[app]=TRUE;
}
/* Enables writes to the buffer from a specific applications */
void unBlockPoApp(AppType app)
{
blocked[app]=FALSE;
}
/* Disables writes to the buffer from all applications */
void blockAllPoApps(void)
{
int i;
for(i=0; i<DOSC_APP_TYPE_SIZE; i++)
blocked[i] = TRUE;
}
/* Enables writes to the buffer from all applications */
void unBlockAllPoApps(void)
{
int i;
for(i=0; i<DOSC_APP_TYPE_SIZE; i++)
blocked[i] = FALSE;
}
/* Saves a single copy of the current list of blocked apps */
void savePoBlockedApps(void)
{
int i;
for(i=0; i<DOSC_APP_TYPE_SIZE; i++)
blockedBackup[i] = blocked[i];
}
/* Restores a previously saved copy of the list of blocked apps */
void restorePoBlockedApps(void)
{
int i;
for(i=0; i<DOSC_APP_TYPE_SIZE; i++)
blocked[i] = blockedBackup[i];
}
/* Counts the number of apps currently blocked */
int countUnblockedApps(void)
{
int i, ret;
for(i=0, ret=0; i<DOSC_APP_TYPE_SIZE; i++)
if(blocked[i] == FALSE) ret++;
return ret;
}
/* Used for a telnet-style connection to the program */
void printFromOffset_interface(void)
{
printPoLogFromOffset(getInt("Skip how many", 0, 999, 0));
}
void blockAnApp_interface(void)
{
blockPoApp(getInt("Which app? [0=DOSC_LINK, 1=DOSC_NETWORK, 2=DOSC_TRANSPORT, 3=DOSC_NL_BUFF, 4=DOSC_TL_BUFF]", 0, 4, 0));
}
void unBlockAnApp_interface(void)
{
unBlockPoApp(getInt("Which app? [0=DOSC_LINK, 1=DOSC_NETWORK, 2=DOSC_TRANSPORT, 3=DOSC_NL_BUFF, 4=DOSC_TL_BUFF]", 0, 4, 0));
}
void currentBufferSize_interface(void)
{
printf("Current buffer has %i entries.\n", poLogBuff.count);
}
/* Used for a telnet-style connection to the program */
void printLastMessages_interface(void)
{
printLastMessages(getInt("Show how many", 0, 999, 0));
}
/* this initializes the buffer & the blocked list */
void dosclogsi_entry (void)
{
#ifndef LOCAL_COMPILE
static mon_cmd_rec mainList, mainEntry, print, pageOn, pageOff, clear, save, restore, blockAll, unBlockAll, printOffset, blockAnApp, unBlockAnApp, buffSize, printLast;
#endif
/* Initialize the buffer internal pointers */
clear_po_log();
/* Start with page mode off */
pageMode = DOSC_ON;
/* Enable every application to write to the buffer */
unBlockAllPoApps();
/* By default, we only log to the po buffer. */
logDestination = toBuffer;
#ifndef LOCAL_COMPILE
/* Create all MCE monitor commands under "DoscLog" directory */
MON_add_dir("DoscLog", &mainList);
/* MON_add_sub_cmd("Main", main, &mainList, &mainEntry); */
MON_add_sub_cmd("PrintLog", (void (*)(void))print_po_log, &mainList, &print);
MON_add_sub_cmd("PagingOn", turnPoPagingOn, &mainList, &pageOn);
MON_add_sub_cmd("PagingOff", turnPoPagingOff, &mainList, &pageOff);
MON_add_sub_cmd("ClearLog", clear_po_log, &mainList, &clear);
MON_add_sub_cmd("SaveApps", savePoBlockedApps, &mainList, &save);
MON_add_sub_cmd("RestoreApps", restorePoBlockedApps, &mainList, &restore);
MON_add_sub_cmd("BlockAll", blockAllPoApps, &mainList, &blockAll);
MON_add_sub_cmd("UnBlockAll", unBlockAllPoApps, &mainList, &unBlockAll);
MON_add_sub_cmd("PrintFromOffset", printFromOffset_interface, &mainList, &printOffset);
MON_add_sub_cmd("BlockAnApp", blockAnApp_interface, &mainList, &blockAnApp);
MON_add_sub_cmd("UnBlockAnApp", unBlockAnApp_interface, &mainList, &unBlockAnApp);
MON_add_sub_cmd("CurrentLogSize", currentBufferSize_interface, &mainList, &buffSize);
MON_add_sub_cmd("NewestMessages", printLastMessages_interface, &mainList, &printLast);
#endif
}
/*************************************************************************
** Function: getInt
** Purpose: To retrieve an integer from the input buffer.
** Parameters:
** str - (char*) the prompt to display.
** low,high - (int) the inclusive bounds of the allowable values.
** Default - if no valid integer is input, then this default value is
** returned. This value is displayed in []'s in the prompt.
** Notes:
** If an out-of-bounds value is entered, a error message is displayed,
** and another value must be entered.
** Return value: (int) the entered value, or the Default.
*************************************************************************/
int getInt(char* str, int low, int high, int Default)
{
int ret;
char* line;
do {
printf("%s [%d]: ", str, Default);
line = MON_get_line();
if(sscanf(line, " %d", &ret)<=0) return Default;
if(ret<low || ret>high) printf("The value must be in the range %d to %d\n", low, high);
} while(ret<low || ret>high);
return ret;
}
--------------39487F263D904C57CA8F2F14
Content-Type: text/plain; charset=us-ascii;
name="dosclogsi.aa02"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="dosclogsi.aa02"
INTERFACE DOSCLOGSI USES SIENCPUI, MONUI, SISWERGI;
$LI ENTRY dosclogsi_entry
/* EDITION AA02 (PEG00), UNXDEV PBEER.50 (99/07/21 21:59:00) -- OPEN */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef LOCAL_COMPILE
#define FALSE 0
#define TRUE 1
#endif
/* This is the number of characters which can be stored in each entry in messaging buffer */
#define PO_LINE_WIDTH 80
/* Each value in this enum represents an application that can post a message to
the buffer. To add a new application, add an element before DOSC_APP_TYPE_SIZE */
typedef enum {DOSC_LINK=0, DOSC_NETWORK, DOSC_TRANSPORT, DOSC_NL_BUFF, DOSC_TL_BUFF, DOSC_APP_TYPE_SIZE} AppType;
/* Scratch pad area. */
extern char potxt[PO_LINE_WIDTH*2+1];
/* Used to write a log entry. */
void writePoLog(AppType app, char *text);
/* Used to print the entire contents of the log buffer to screen. */
int print_po_log(void);
/* Used to reset(empty) the log buffer. */
void clear_po_log(void);
/* Returns the number of applications which are currently blocked */
int countUnblockedApps(void);
/* Prints the message buffer, skipping the first 'offset' messages */
int printPoLogFromOffset(int offset);
/* Blocks a specified application 'app' from posting messages */
void blockPoApp(AppType app);
/* Enables a specified application 'app' to post messages */
void unBlockPoApp(AppType app);
/* Enables all applications to post messages */
void unBlockAllPoApps(void);
/* Blocks all applications from posting messages */
void blockAllPoApps(void);
/* These 2 functions toggle paging mode. If it is off when messages are displayed,
all messages are printed without a break. If it is on, messages are printed
one page a time and wait for user input. */
void turnPoPagingOff(void);
void turnPoPagingOn(void);
/* saves a copy of the list of blocked applications. This only saves a single
copy, and if savePoBlockedApps is called twice before a restorePoBlockedApps
is called, the first stored list is gone! A stored list can be restored
multiple times. */
void savePoBlockedApps(void);
void restorePoBlockedApps(void);
/* Causes all logging to be redirected to the screen/buffer/file. */
void logs_to_screen(void);
void logs_to_buffer(void);
#ifdef LOCAL_COMPILE
void logs_to_file(void);
#endif
void printFromOffset_interface(void);
void blockAnApp_interface(void);
void unBlockAnApp_interface(void);
void currentBufferSize_interface(void);
void printLastMessages_interface(void);
/* entry code */
void dosclogsi_entry(void);
int getInt(char* str, int low, int high, int Default);
#ifdef LOCAL_COMPILE
char* MON_get_line(void)
{
static char line[100];
int chr;
if((chr=getc(stdin))!='\n') ungetc(chr, stdin);
else return "";
scanf(" %99[^\n]", line);
if((chr=getc(stdin))!='\n') ungetc(chr, stdin);
return line;
}
#endif
--------------39487F263D904C57CA8F2F14
Content-Type: text/plain; charset=us-ascii;
name="checksum.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="checksum.c"
#include <stdio.h>
typedef unsigned char byte;
byte AM[] = "223456789AZC";
byte SP[] = "abcdefghijkl";
byte checkSum(byte* AM, byte* SP)
{
byte sum=0;
int i;
for(i=0; i<12; i++) {
if(i!=10) sum+=AM[i];
sum+=SP[i];
}
return sum;
}
int main()
{
AM[10]=checkSum(AM,SP);
printf("AM=%s\n", AM);
return 0;
}
--------------39487F263D904C57CA8F2F14--
- Raw text -