⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bbc.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* bbc.c - ZOTnet BBoard checker */#ifndef	lintstatic char ident[] = "@(#)$Id: bbc.c,v 2.13 1993/02/26 21:58:57 jromine Exp $";#endif	lint#include "../h/mh.h"#include "../zotnet/bboards.h"#include <stdio.h>#ifdef	BPOP#include "../zotnet/mts.h"#endif	BPOP#include <errno.h>#include <signal.h>#ifndef	sigmask#define	sigmask(s)	(1 << ((s) - 1))#endif	not sigmask#ifdef	ridge#undef	SIGTSTP#endif	ridge#include <sys/types.h>#include <sys/stat.h>#ifdef	SIGTSTP#include <sys/wait.h>#include <sys/time.h>#include <sys/resource.h>#endif	SIGTSTP#ifdef LOCALE#include	<locale.h>#endif#define	RCFILE	".bbrc"#define	NBB	100/*  */static struct swit switches[] = {#define	TOPICSW	0    "topics", 6,#define	CHECKSW	1    "check", 5,#define	READSW	2    "read", 4,#define	QUIETSW	3    "quiet", 4,#define	VERBOSW	4    "verbose", 4,#define ARCHSW	5    "archive", 4,#define NOARCH  6    "noarchive", 3,#define	PROTSW	7    "protocol", 4,#define	NPROTSW	8    "noprotocol", 3,#define	PROGSW	9    "mshproc program", 4,#define	RCSW	10    "rcfile rcfile", 4,#define	NRCSW	11    "norcfile", 3,#define	FILESW	12    "file BBoardsfile", 4,#define	USERSW	13    "user BBoardsuser",#ifndef	NNTP	4,#else	NNTP	-4,#endif	NNTP#define	HOSTSW	14    "host host",#ifndef	BPOP    -4,#else	BPOP    4,#endif	BPOP#define	RPOPSW	15    "rpop",#ifndef	RPOP	-4,#else	RPOP	4,#endif	RPOP#define	NRPOPSW	16    "norpop",#ifndef	RPOP	-6,#else	RPOP	6,#endif	RPOP#define	HELPSW	17    "help", 4,    NULL, NULL};struct bbcount {    char   *key;    int     count;    struct bbcount *left;    struct bbcount *right;};/*  */extern int  errno;static int  changed = 0;static int  oops = 0;static int  quitting = 0;static int  archivesw = 0;static int  checksw = 0;static int  protsw = 1;static int  quietsw = 0;static int  readsw = 0;static int  topicsw = 0;static int  verbosw = 0;static int  didpop = OK;static int  rpop = 1;static char *user = BBOARDS;static char *host = NULL;#ifdef	BPOPextern char response[];extern char   *getusr ();static char  **getip ();#endif	BPOPTYPESIG	sigser (), hupser ();int	action ();#ifdef	SIGTSTPint	tstpid;static  TYPESIG	tstpser ();#endif	SIGTSTPstatic char *rcfile=NULL;static struct bbcount  *bbc = NULL;static struct bboard   *bbl = NULL;struct bbcount *add_count (), *seek_count ();struct bboard *getbbaux (), *getbbvis ();static	void	bbreset();#ifdef	UCLextern	char	   *bbs[];extern	int	   called_bbc;static	int bbp;#endif	UCL/*  *//* ARGSUSED */main (argc, argv)int     argc;char  **argv;{#ifndef	UCL    int	    bbp = 0,	    vecp = 1;#else	UCL    int    vecp = 1;#endif	UCL    char   *cp,	   *rc=NULL,          **ap,          **argp,            buffer[80],           *arguments[MAXARGS],#ifndef	UCL	   *bbs[NBB + 1],#endif	UCL	   *vec[MAXARGS];#ifdef	UCL    called_bbc = 1;    bbp = 0;#endif	UCL#ifdef LOCALE	setlocale(LC_ALL, "");#endif    invo_name = r1bindex (argv[0], '/');#ifdef	BPOP    mts_init (invo_name);    if (popbbhost && *popbbhost)	host = popbbhost;    if (popbbuser && *popbbuser)	user = popbbuser, rpop = 0;#endif	BPOP    if ((cp = m_find (invo_name)) != NULL) {	ap = brkstring (cp = getcpy (cp), " ", "\n");	ap = copyip (ap, arguments);    }    else	ap = arguments;    (void) copyip (argv + 1, ap);    argp = arguments;    (void) setbbent (SB_STAY);/*  */    while (cp = *argp++) {	if (*cp == '-')	    switch (smatch (++cp, switches)) {		case AMBIGSW: 		    ambigsw (cp, switches);		    done (1);		case UNKWNSW: 		   vec[vecp++] = --cp;		   continue;		case HELPSW: 		    (void) sprintf (buffer,		    	"%s [bboards ...] [switches] [switches for mshproc]",			invo_name);	    	    help (buffer, switches);		    done (1);		case TOPICSW: 		    topicsw++;		    checksw = readsw = 0;		    continue;		case CHECKSW: 		    checksw++;		    readsw = topicsw = 0;		    continue;		case READSW: 		    readsw++;		    checksw = topicsw = 0;		    continue;		case ARCHSW: 		    archivesw++;		    continue;		case NOARCH: 		    archivesw = 0;		    continue;		case PROTSW: 		    protsw++;		    continue;		case NPROTSW: 		    protsw = 0;		    continue;		case QUIETSW: 		    quietsw++;		    verbosw = 0;		    continue;		case VERBOSW: 		    verbosw++;		    quietsw = 0;		    continue;		case PROGSW:		    if (!(mshproc = *argp++) || *mshproc == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    continue;		case RCSW:		    if (!(rc = *argp++) || *rc == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    continue;		case NRCSW:		    rc = NULL;		    continue;		case FILESW:		    if (!(cp = *argp++) || *cp == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    if (!setbbinfo (user, cp, 1))			adios (NULLCP, "setbbinfo(%s, %s, 1) failed -- %s",				user, cp, getbberr ());		    continue;		case USERSW:		    if (!(user = *argp++) || *user == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    continue;		case HOSTSW:		    if (!(host = *argp++) || *host == '-')			adios (NULLCP, "missing argument to %s", argp[-2]);		    didpop = NOTOK;		    continue;		case RPOPSW:		    rpop++;		    continue;		case NRPOPSW:		    rpop = 0;		    continue;	    }	if (bbp < NBB)	    bbs[bbp++] = cp;	else	    adios (NULLCP, "too many bboards, starting with %s", cp);    }    bbs[bbp] = NULL;/*  */#ifdef	BPOP    if (host && !*host)	host = NULL, didpop = OK;    if (!host || !rpop)	(void) setuid (getuid ());#endif	BPOP    if (!m_find ("path"))	free (path ("./", TFOLDER));    rcinit (rc);    for (bbp = 0; cp = bbs[bbp]; bbp++)	add_bb (cp, NOTOK);#ifdef UCL    if (topicsw) {	called_bbc = 0;	topics ();	}#else    if (topicsw)	topics ();#endif    else {	default_bboards ();	if (checksw)	    check ();	else	    process (vecp, vec);    }#ifdef	BPOP    if (didpop != OK && pop_quit () == NOTOK)	adios (NULLCP, "%s", response);#endif	BPOP    done (0);}/*  */topics () {    register char  *cp,                  **ap;    register struct bboard *bb;    printf ("%16s %s   %s\n", "BBoard", "Items",	    verbosw ? "Interesting Facts" : "Last Update");    printf ("%16s %s   %s\n", "------", "-----",	    verbosw ? "-----------------" : "-----------");    for (bb = bbl ? bbl : getbbvis ();	    bb;	    bb = bbl ? bb -> bb_link : getbbvis ()) {	printf ("%16s %5d   %s\n",		bb -> bb_name, bb -> bb_maxima,		bb -> bb_date ? bb -> bb_date : "no deliveries");	if (verbosw) {	    if (*bb -> bb_aka) {		cp = NULL;		for (ap = bb -> bb_aka; *ap; ap++)		    cp = add (*ap, cp ? add (", ", cp) : cp);		printv ("AKA", cp);		free (cp);	    }	    printv ("Leaders", *bb -> bb_leader);	    for (ap = bb -> bb_leader + 1; *ap; ap++)		printv (NULLCP, *ap);	    printv ("File", bb -> bb_file);	    printv ("Archive", bb -> bb_archive);	    printv ("Info", bb -> bb_info);	    printv ("Map", bb -> bb_map);	    printv ("Password", bb -> bb_passwd);	    if (strcmp (bb -> bb_name, bb -> bb_addr))		printv ("Address", bb -> bb_addr);	    if (strcmp (*bb -> bb_leader, bb -> bb_request))		printv ("Request", bb -> bb_request);	    if (*bb -> bb_relay)		printv ("Relay", bb -> bb_relay);	    if (*bb -> bb_dist) {		changed = 0;		(void) getbbdist (bb, action);		if (!changed)		    printv ("Dist", "");		if (cp = getbberr ())		    printv ("Error", cp);	    }	    printb (bb -> bb_flags & ~BB_SEEN);	}    }}/*  */printv (key, value)register char   *key,	        *value;{    char    buffer[BUFSIZ];    if (key)	(void) sprintf (buffer, "%s: ", key);    else	buffer[0] = '\0';    printf ("%*s%-*s", 25, "", 10, buffer);    if (value && *value)	printf ("%s", value);    (void) putchar ('\n');}int     action (local, domain)register char   *local,		*domain;{    char    buffer[BUFSIZ];    (void) sprintf (buffer, "%s@%s", local, domain);    printv (changed++ ? NULL : "Dist", buffer);    return 0;}printb (flags)unsigned int flags;{    char buffer[BUFSIZ];    printv ("Flags", sprintb (buffer, flags, BBITS));}/*  */check () {#define	grammar(a,b,c)	(a == 1 ? b : c)#define	plural(d)	grammar(d, "", "s")    int     diff;    register struct bboard  *bb;    for (bb = bbl; bb; bb = bb -> bb_link) {	diff = bb -> bb_maxima - bb -> bb_count;	if (quietsw) {	    if (diff > 0)		printf ("%s -- %d item%s unseen\n",			bb -> bb_name, diff, plural (diff));	}	else	    if (bb -> bb_maxima == 0)		printf ("%s -- empty\n", bb -> bb_name);	    else		if (bb -> bb_count == 0)		    printf ("%s -- %d item%sseen)\n",			    bb -> bb_name, bb -> bb_maxima,			    grammar (bb -> bb_maxima, " (un", "s (none "));		else		    if (diff <= 0)			printf ("%s -- %d item%s (all seen)\n",				bb -> bb_name, bb -> bb_maxima,				plural (bb -> bb_maxima));		    else			printf ("%s -- %d item%s unseen\n",				bb -> bb_name, diff, plural (diff));    }}/*  */process (vecp, vec)int	vecp;char   *vec[];{    int     diff;#ifdef	SIGTSTP    TYPESIG	    (*tstat) ();#endif	SIGTSTP    register struct bboard *bb;    vec[0] = r1bindex (mshproc, '/');#ifdef	SIGTSTP    tstat = signal (SIGTSTP, tstpser);#endif	SIGTSTP    for (bb = bbl; bb && !quitting; bb = bb -> bb_link) {	diff = bb -> bb_maxima - bb -> bb_count;	if (bb -> bb_maxima == 0) {	    if (!quietsw)		printf ("%s -- empty\n", bb -> bb_name);	    continue;	}	else {	    if (diff < 0) {		printf (		"Oops! looks like someone reset %s -- assuming all unseen\n",		    bb -> bb_name);		diff = bb -> bb_maxima;		bbreset (bb, 0);	    }	    if (verbosw || archivesw || diff > 0)		bbread (bb, vecp, vec);	    else		if (!quietsw)		    printf ("%s -- %d item%s (all seen)\n",			    bb -> bb_name, bb -> bb_maxima,			    plural (bb -> bb_maxima));	}    };#ifdef	SIGTSTP    (void) signal (SIGTSTP, tstat);#endif	SIGTSTP    rcend ();}/*  */#ifdef	BPOP/* ARGSUSED */static int  xtnd1 (s)char   *s;{    return OK;}#endif	BPOP/*  */bbread (bb, vecp, vec)register struct bboard  *bb;int	vecp;char   *vec[];{    int     child_id,            pd[2];    char    buf1[BUFSIZ],            buf2[BUFSIZ],            buf3[BUFSIZ];#ifdef	BPOP    int	    nmsgs,	    nbytes;    char    buf4[BUFSIZ],            buf5[BUFSIZ];#endif	BPOP    struct stat st;#ifdef	BPOP    if (bb -> bb_flags & BB_REMOTE) {	if (pop_xtnd (xtnd1, "%s %s", archivesw ? "archive" : "bboards",			bb -> bb_name) == NOTOK) {	    advise (NULLCP, "%s", response);	    return;	}	if (pop_stat (&nmsgs, &nbytes) == NOTOK)	    adios (NULLCP, "%s", response);	if (nmsgs == 0) {	    if (verbosw)		printf ("%s -- empty\n", bb -> bb_name);	    return;	}	if (pop_fd (buf4, buf5) == NOTOK)	    adios (NULLCP, "%s", response);    }    else#endif	BPOP    if (stat (archivesw ? bb -> bb_archive : bb -> bb_file, &st) != NOTOK	    && st.st_size == 0)	return;    if (protsw) {	if (pipe (pd) == NOTOK)	    adios ("pipe", "unable to");	(void) sprintf (buf3, "%d", getpid ());    }    switch (child_id = fork ()) {	case NOTOK: 	    adios ("fork", "unable to");	case OK: 	    if (protsw) {		(void) close (pd[0]);		(void) sprintf (buf1, "%d", bb -> bb_count + 1);		(void) sprintf (buf2, "%d", pd[1]);		vec[vecp++] = "-idname";		vec[vecp++] = bb -> bb_name;		vec[vecp++] = "-idstart";		vec[vecp++] = buf1;		vec[vecp++] = "-idstop";		vec[vecp++] = buf2;		vec[vecp++] = "-idquit";		vec[vecp++] = buf3;	    }#ifdef	BPOP	    if (bb -> bb_flags & BB_REMOTE) {		vec[vecp++] = "-popread";		vec[vecp++] = buf4;		vec[vecp++] = "-popwrite";		vec[vecp++] = buf5;	    }#endif	BPOP	    vec[vecp++] = archivesw ? bb -> bb_archive : bb -> bb_file;	    vec[vecp] = NULL;	    execvp (mshproc, vec);	    fprintf (stderr, "unable to exec ");	    perror (mshproc);	    _exit (-1);	default: #ifdef	SIGTSTP	    tstpid = child_id;#endif	SIGTSTP	    if (protsw) {		(void) close (pd[1]);		pgmread (pd[0], child_id, bb);	    }	    else		(void) pidXwait (child_id, mshproc);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -