reformat.

This commit is contained in:
Kelvin Sherlock 2019-01-16 21:26:42 -05:00
parent 9ef349f561
commit 267e1803d0
2 changed files with 335 additions and 292 deletions

4
.clang-format Normal file
View File

@ -0,0 +1,4 @@
---
IndentWidth: '4'
...

171
nscda.c
View File

@ -33,16 +33,15 @@
#include <tcpip.h> #include <tcpip.h>
#include <tcpipx.h> #include <tcpipx.h>
#include <memory.h>
#include <misctool.h> #include <misctool.h>
#include <texttool.h> #include <texttool.h>
#include <memory.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
static char buffer[80]; static char buffer[80];
const char Header1[] = const char Header1[] =
" Ipid State Address sPort dPort RcvQueue SendQueue\r"; " Ipid State Address sPort dPort RcvQueue SendQueue\r";
const char Header2[] = const char Header2[] =
@ -120,14 +119,8 @@ void Display(Word ipid, srBuff *srBuffer) {
} }
asm int ReadKey(void) { asm int ReadKey(void) {
sep #0x20 sep #0x20 loop : lda > 0xe0c000 bpl loop sta > 0xe0c010 rep #0x20 and
loop: #0x7f rtl
lda >0xe0c000
bpl loop
sta >0xe0c010
rep #0x20
and #0x7f
rtl
} }
/* ORCA Console control codes */ /* ORCA Console control codes */
@ -156,7 +149,8 @@ int ReadInt(void) {
break; break;
} }
if (c == 13) { if (c == 13) {
if (i == 0) rv = -1; if (i == 0)
rv = -1;
break; break;
} else if ((c == 8) || (c == 0x7f)) { } else if ((c == 8) || (c == 0x7f)) {
if (i) { if (i) {
@ -181,19 +175,17 @@ int ReadInt(void) {
return rv; return rv;
} }
void hexdump(const void *data, Word length) {
void hexdump(const void *data, Word length) Word i;
{ Word j;
Word i; Word k;
Word j; Word x;
Word k;
Word x;
static char text[17]; static char text[17];
if (length > 16 * 320) length = 16 * 320; if (length > 16 * 320)
length = 16 * 320;
for (i = 0, j = 0, x = 0; i < length; i++) for (i = 0, j = 0, x = 0; i < length; i++) {
{
k = ((unsigned char *)data)[i]; k = ((unsigned char *)data)[i];
buffer[j++] = "0123456789abcdef"[k >> 4]; buffer[j++] = "0123456789abcdef"[k >> 4];
@ -202,10 +194,10 @@ Word x;
text[x++] = isprint(k) ? k : '.'; text[x++] = isprint(k) ? k : '.';
if ((i & 0x0f) == 0x07) buffer[j++] = ' '; if ((i & 0x0f) == 0x07)
buffer[j++] = ' ';
if ((i & 0x0f) == 0x0f) if ((i & 0x0f) == 0x0f) {
{
buffer[j++] = ' '; buffer[j++] = ' ';
buffer[j++] = 0; buffer[j++] = 0;
text[x++] = 0; text[x++] = 0;
@ -216,17 +208,34 @@ Word x;
} }
} }
if (i & 0x0f) if (i & 0x0f) {
{ while (j < 52)
while (j < 52) buffer[j++] = ' '; buffer[j++] = ' ';
buffer[j++] = 0; buffer[j++] = 0;
text[x++] = 0; text[x++] = 0;
printf("%04x: %s%s\r", i - 15, buffer, text); printf("%04x: %s%s\r", i - 15, buffer, text);
} }
} }
void DisplayQueue(Word which, const userRecord *rec) {
Handle h;
Word size;
putchar(0x0c);
if (which == 'S') {
fputs("Send Queue\r\r");
h = (Handle)rec->uwTCPDataOut;
} else {
fputs("Receive Queue\r\r");
h = (Handle)rec->uwTCPDataIn;
}
if (h) {
size = GetHandleSize(h);
hexdump(*h, size);
}
}
void DisplayDP(void) { void DisplayDP(void) {
@ -239,8 +248,6 @@ void DisplayDP(void) {
hexdump((void *)dp, 0x0100); hexdump((void *)dp, 0x0100);
} }
void DisplayLinkLayer(void) { void DisplayLinkLayer(void) {
static linkInfoBlk link; static linkInfoBlk link;
variablesPtr lv; variablesPtr lv;
@ -268,7 +275,6 @@ void DisplayLinkLayer(void) {
printf("RefCon: $%08lx\r", lv->lvRefCon); printf("RefCon: $%08lx\r", lv->lvRefCon);
printf("Errors: $%08lx\r", lv->lvErrors); printf("Errors: $%08lx\r", lv->lvErrors);
printf("MTU: %d\r", lv->lvMTU); printf("MTU: %d\r", lv->lvMTU);
} }
void DisplayTCP(void) { void DisplayTCP(void) {
@ -306,42 +312,72 @@ void DisplayTCP(void) {
printf("Alive Flag: $%04x\r", TCPIPGetAliveFlag()); printf("Alive Flag: $%04x\r", TCPIPGetAliveFlag());
printf("Alive Minutes: %d\r", TCPIPGetAliveMinutes()); printf("Alive Minutes: %d\r", TCPIPGetAliveMinutes());
printf("Login Count: %d\r", TCPIPGetLoginCount()); printf("Login Count: %d\r", TCPIPGetLoginCount());
} }
unsigned DisplayIpid(unsigned ipid) { unsigned DisplayIpid(unsigned ipid) {
/* extended debug information */ /* extended debug information */
enum { MAX_PAGE = 0; };
Handle h; Handle h;
Word size; Word size;
unsigned page = 0; unsigned page = 0;
userRecord *rec;
unsigned c;
putchar(0x0c); putchar(0x0c);
printf("IPID: %d\r", ipid); printf("IPID: %d\r", ipid);
h = (Handle)TCPIPGetUserRecord(ipid); h = (Handle)TCPIPGetUserRecord(ipid);
if (_toolErr) return; if (_toolErr || !h) {
if (!h) return; printf("\r\rInvalid PID");
ReadKey();
return;
}
size = (Word)GetHandleSize(h); size = (Word)GetHandleSize(h);
rec = (userRecord *)*h;
printf("Datagram count (all): %d\r", for (;;) {
TCPIPGetDatagramCount(ipid, protocolAll));
printf("Datagram count (icmp): %d\r", switch (page) {
case 0:
break;
}
for (;;) {
c = ReadKey();
if (c == 0x1b || c == 'Q' || c == 'q')
return;
if (c == LEFT) {
if (page == 0)
page = MAX_PAGE;
else
--page;
break;
}
if (c == RIGHT) {
if (page == MAX_PAGE)
page = 0;
else
++page;
break;
}
SysBeep();
}
}
}
printf("Datagram count (all): %d\r", TCPIPGetDatagramCount(ipid, protocolAll));
printf("Datagram count (icmp): %d\r",
TCPIPGetDatagramCount(ipid, protocolICMP)); TCPIPGetDatagramCount(ipid, protocolICMP));
printf("Datagram count (tcp): %d\r", printf("Datagram count (tcp): %d\r", TCPIPGetDatagramCount(ipid, protocolTCP));
TCPIPGetDatagramCount(ipid, protocolTCP));
printf("Datagram count (udp): %d\r", printf("Datagram count (udp): %d\r", TCPIPGetDatagramCount(ipid, protocolUDP));
TCPIPGetDatagramCount(ipid, protocolUDP));
printf("User statistic 1: $%08lx\r", TCPIPGetUserStatistic(ipid, 1));
printf("User statistic 1: $%08lx\r", printf("User statistic 2: $%08lx\r", TCPIPGetUserStatistic(ipid, 2));
TCPIPGetUserStatistic(ipid, 1));
printf("User statistic 2: $%08lx\r",
TCPIPGetUserStatistic(ipid, 2));
} }
void DisplayIpids(void) { void DisplayIpids(void) {
@ -359,7 +395,8 @@ void DisplayIpids(void) {
line = 2; line = 2;
count = TCPIPGetLoginCount(); count = TCPIPGetLoginCount();
if (!count) return; if (!count)
return;
/* in theory, there could be 50 ipids. */ /* in theory, there could be 50 ipids. */
/* 20 ought to be enough */ /* 20 ought to be enough */
@ -373,20 +410,20 @@ void DisplayIpids(void) {
--count; --count;
++line; ++line;
if (count == 0) return; if (count == 0)
if (line == 23) return; return;
if (line == 23)
return;
} }
} }
void DisplayMain(void) { void DisplayMain(void) {
enum { enum { MAX_PAGE = 3 };
MAX_PAGE = 3
};
char c; char c;
unsigned page = 0; unsigned page = 0;
for(;;) { for (;;) {
switch (page) { switch (page) {
case 0: case 0:
@ -416,17 +453,22 @@ void DisplayMain(void) {
fputs("Q: Quit", stdout); fputs("Q: Quit", stdout);
} }
for(;;) { for (;;) {
c = ReadKey(); c = ReadKey();
if (c == 'Q' || c == 'q' || c == ESC) return; if (c == 'Q' || c == 'q' || c == ESC)
return;
if (c == LEFT) { if (c == LEFT) {
if (page == 0) page = MAX_PAGE; if (page == 0)
else --page; page = MAX_PAGE;
else
--page;
break; break;
} }
if (c == RIGHT) { if (c == RIGHT) {
if (page == MAX_PAGE) page = 0; if (page == MAX_PAGE)
else ++page; page = 0;
else
++page;
break; break;
} }
if (c == 'I' || c == 'i') { if (c == 'I' || c == 'i') {
@ -438,7 +480,8 @@ void DisplayMain(void) {
fputs("ipid: ", stdout); fputs("ipid: ", stdout);
int ipid = ReadInt(); int ipid = ReadInt();
if (ipid < 0) goto menu; if (ipid < 0)
goto menu;
DisplayIpid(ipid); DisplayIpid(ipid);
break; break;
} }
@ -447,9 +490,6 @@ void DisplayMain(void) {
} }
} }
void StartUp(void) { void StartUp(void) {
putchar(CURSOR_OFF); /* turn off cursor */ putchar(CURSOR_OFF); /* turn off cursor */
@ -461,5 +501,4 @@ void StartUp(void) {
DisplayMain(); DisplayMain();
} }
void ShutDown(void) { void ShutDown(void) {}
}