From: "Campbell, Rolf [SKY:1U32:EXCH]" 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 Content-Type: multipart/mixed; boundary="------------39487F263D904C57CA8F2F14" 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 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; i0) ret=FALSE; else { int numElements=poLogBuff.count-offset, linesPrinted=0; for(i=0; i80))) { 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; ihigh) printf("The value must be in the range %d to %d\n", low, high); } while(rethigh); 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 #include #include #include #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 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--