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'
...

157
nscda.c
View File

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