Article View: comp.archives
Article #5645A program to display site entries
From: comp.archives
Date: Wed, 05 Apr 1989 09:35
Date: Wed, 05 Apr 1989 09:35
183 lines
4903 bytes
4903 bytes
Here is a short C program to display site entries. This is just a
program I whipped up in an hour or so; it is completely uncommented
and only robust enough to deal with properly formatted site entries,
but it seems to work fine with those. Since it ignores any line that
doesn't begin like a site entry line, you can use it to display things
like the mail returned by the comp.archives server.
Its main advantage is that it is short and simple; short enough that
I don't mind posting it here, anyway. :-)
Call it with a list of files to display. If you call it with no
arguments, it will read from the standard input.
No doubt there is at least one very silly and very fatal bug in here.
Let me know if you find one. :-)
---
Bill
{ uunet | novavax } !twwells!bill
send comp.archives postings to twwells!comp-archives
send comp.archives related mail to twwells!comp-archives-request
---
#include <stdio.h>
#include <ctype.h>
extern char *strchr();
char *Splitbuf[80];
char Buf[1024];
char *
skipsp(ptr)
register char *ptr;
{
while (isspace(*ptr)) {
++ptr;
}
return (ptr);
}
char *
findnext(ptr)
register char *ptr;
{
while (*ptr && !isspace(*ptr)) {
++ptr;
}
return (skipsp(ptr));
}
void
splitup()
{
register char *ptr;
register int i;
for (ptr = skipsp(Buf + 2), i = 0; ; *ptr++ = 0) {
Splitbuf[i++] = ptr;
if (!(ptr = strchr(ptr, ';'))) {
Splitbuf[i] = 0;
return;
}
}
}
void
printfile(name)
char *name;
{
register char *ptr;
register char *str;
FILE *fp;
int i;
if (!name) {
fp = stdin;
} else if (!(fp = fopen(name, "r"))) {
fprintf(stderr, "Unable to open site file %s\n", name);
}
while (fgets(Buf, sizeof(Buf), fp)) {
if (Buf[0] == 'D' && Buf[1] == 'E') {
if (Buf[2] != '\n') {
printf("\t%s", Buf + 3);
} else {
printf(" |\n");
}
continue;
}
if (!*(ptr = skipsp(Buf + 2))) {
continue;
}
if (str = strchr(Buf + 2, '\n')) {
*str = 0;
}
if (Buf[0] == 'N' && Buf[1] == 'M') {
printf("\nArchive name: %s\n", ptr);
} else if (Buf[0] == 'T' && Buf[1] == 'M') {
splitup();
switch (*ptr) {
case 'C': ptr = "Central"; break;
case 'E': ptr = "Eastern"; break;
case 'M': ptr = "Mountain"; break;
case 'P': ptr = "Pacific"; break;
}
printf(
"The archive is located in the %s time zone\n",
ptr);
if (Splitbuf[1]) {
printf("Times to call: %s", Splitbuf[1]);
for (i = 2; Splitbuf[i]; ++i) {
printf(",%s", Splitbuf[i]);
}
printf("\n");
}
} else if (Buf[0] == 'T' && Buf[1] == 'T') {
printf("Archive title: %s\n", ptr);
} else if (Buf[0] == 'A' && Buf[1] == 'D') {
printf("The archive administrator is: %s\n", ptr);
} else if (Buf[0] == 'M' && Buf[1] == 'A') {
printf("The mailing address is:\n");
while (str = strchr(ptr, ';')) {
*str++ = 0;
printf("\t%s\n", ptr);
ptr = skipsp(str);
}
printf("\t%s\n", ptr);
} else if (Buf[0] == 'C' && Buf[1] == 'O') {
splitup();
if (strcmp(Splitbuf[0], "bbs") == 0) {
printf(
"BBS access: phone %s; modem settings: %s; protocols: %s\n",
Splitbuf[2], Splitbuf[3], Splitbuf[4]);
} else if (strcmp(Splitbuf[0], "fido") == 0) {
printf("Fidonet access: %s\n", Splitbuf[2]);
} else if (strcmp(Splitbuf[0], "ftp") == 0) {
printf("Ftp access: %s[%s]",
Splitbuf[2], Splitbuf[3]);
if (Splitbuf[4][0]) {
printf(", directory %s",
Splitbuf[4]);
}
printf("\n");
} else if (strcmp(Splitbuf[0], "mail") == 0) {
printf(
"Mail access: address %s; send the following for help:\n",
Splitbuf[2]);
for (i = 3; Splitbuf[i]; ++i) {
printf("\t%s\n", Splitbuf[i]);
}
} else if (strcmp(Splitbuf[0], "uucp") == 0) {
printf(
"UUCP access: for directory %s, the L.sys entry is:\n",
Splitbuf[2]);
printf("\t%s\n", Splitbuf[3]);
}
} else if (Buf[0] == 'I' && Buf[1] == 'X') {
splitup();
printf(
"Index file (%s): %s, containing %s.\n",
Splitbuf[0], Splitbuf[1], Splitbuf[5]);
} else if (Buf[0] == 'K' && Buf[1] == 'W') {
printf("Archive keywords: %s\n", ptr);
}
}
fclose(fp);
}
int
main(argc, argv)
int argc;
char **argv;
{
if (argc == 1) {
printfile((char *)0);
} else {
while (--argc > 0) {
printfile(*++argv);
}
}
exit(0);
}
Technical Details
Message-ID:
<820@twwells.uucp>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!novavax!twwells!comparcShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!novavax!twwells!comparc From: comparc@twwells.uucp (comp.archives) Newsgroups: comp.archives Subject: A program to display site entries Message-ID: <820@twwells.uucp> Date: 5 Apr 89 09:35:15 GMT Reply-To: comparc@twwells.UUCP (comp.archives) Organization: None, Ft. Lauderdale Lines: 183 Approved: bill@twwells.uucp (T. William Wells)