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

📄 ipcount.c

📁 早期freebsd实现
💻 C
字号:
From moore.WBST@Xerox.ARPA Tue Sep 10 15:14:08 1985Received: from ucbkim.ARPA by ucbdali.ARPA (5.5/4.48)	id AA10859; Tue, 10 Sep 85 15:13:58 PDTReceived: from UCB-VAX.ARPA (ucbvax.ARPA) by ucbkim.ARPA (5.5/5.3)	id AA00229; Tue, 10 Sep 85 14:28:49 PDTReceived: from Xerox.ARPA (xerox.arpa.ARPA) by UCB-VAX.ARPA (4.24/5.3)	id AA01317; Tue, 10 Sep 85 14:23:25 pdtReceived: from Aurora.ms by ArpaGateway.ms ; 10 SEP 85 14:25:54 PDTDate: 10 Sep 85 17:25:44 EDT (Tuesday)From: moore.WBST@Xerox.ARPASubject: counting pages in a press fileTo: sklower@BERKELEYCc: parmelee@CU-ARPA.CS.CORNELL.EDUMessage-Id: <850910-142554-4998@Xerox>Status: RHi,Here is the hack on iptotext that will count the pages and write them toan accounting file.  I have tried it with both troff generatedinterpress files and Star generated ones.  I don't really understand theBerkeley spooling system (even after glancing at the manual) so I don'tknow if this is what you really want.  What it DOES however, is to takean ip master on the standard input and count the number of pages it has.This information is written to the accounting file which might be namedon the command line.  What it doesn't do is copy the IP master to thestandard output or send the file to a printer.  I hope that this isn't anecessary function...lee#!/bin/sh# This is a shell archive, meaning:# 1. Remove everything above the #!/bin/sh line.# 2. Save the resulting text in a file.# 3. Execute the file with /bin/sh (not csh) to create the files:#	Makefile#	getopt.c#	ipf.c# This archive created: Tue Sep 10 17:12:41 1985export PATH; PATH=/bin:$PATHif test -f 'Makefile'then	echo shar: over-writing existing file "'Makefile'"ficat << \SHAR_EOF > 'Makefile'## Copyright (c) 1984, 1985 Xerox Corp.#DESTINCLUDE=/usr/new/includeDESTBIN=../../../binipf: ipf.o getopt.o	cc -o ipf ipf.o getopt.oipf.o: $(DESTINCLUDE)/iptokens.h $(DESTINCLUDE)/ipnames.h	cc -c -I$(DESTINCLUDE) ipf.clint: 	lint -I$(DESTINCLUDE) ipf.c getopt.cclean:	rm -f ipf *.oinstall: $(DESTBIN)/ipf$(DESTBIN)/ipf: ipf	install -c -s ipf $(DESTBIN)SHAR_EOFif test -f 'getopt.c'then	echo shar: over-writing existing file "'getopt.c'"ficat << \SHAR_EOF > 'getopt.c'/* * getopt - get option letter from argv *	This software is in the public domain *	Originally written by Henry Spenser at the U. of Toronto */#include <stdio.h>char	*optarg;	/* Global argument pointer. */int	optind = 0;	/* Global argv index. */static char	*scan = NULL;	/* Private scan pointer. */extern char	*index();intgetopt(argc, argv, optstring)int argc;char *argv[];char *optstring;{	register char c;	register char *place;	optarg = NULL;	if (scan == NULL || *scan == '\0') {		if (optind == 0)			optind++;			if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] =='\0')			return(EOF);		if (strcmp(argv[optind], "--")==0) {			optind++;			return(EOF);		}			scan = argv[optind]+1;		optind++;	}	c = *scan++;	place = index(optstring, c);	if (place == NULL || c == ':') {		fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);		return('?');	}	place++;	if (*place == ':') {		if (*scan != '\0') {			optarg = scan;			scan = NULL;		} else {			optarg = argv[optind];			optind++;		}	}	return(c);}SHAR_EOFif test -f 'ipf.c'then	echo shar: over-writing existing file "'ipf.c'"ficat << \SHAR_EOF > 'ipf.c'/* *  Interpress utility - count the number of pages in a interpress file * *  Written for Xerox Corporation by Lee Moore & William LeFebvre * * Copyright (c) 1984, 1985 Xerox Corp. * * History: *	 2-sep-85 lee moore	created out of iptotext.c */#ifdef vax11c# include stdio# include setjmp# include ctype# include "iptokens.h"# include "ipnames.h"#else# include <stdio.h># include <setjmp.h># include <ctype.h># include "iptokens.h"# include "ipnames.h"#endifjmp_buf next_file;extern int errno;main(argc, argv)int  argc;char *argv[];{    FILE *acctFile;    int c,	pageCount;    char *login,	 *host;    extern int optind;    extern char *optarg;    login = NULL;    host = NULL;    while ((c = getopt(argc, argv, "cw:l:i:n:h:")) != EOF)	switch (c) {		case 'c':		case 'w':		case 'l':		case 'i':			break;		case 'n':			login = optarg;			break;		case 'h':			host = optarg;			break;		default:			printf("option '%c' not allowed\n");	}    if (argc - optind == 1)    {	pageCount = do_file(stdin);	if( pageCount < 0 )	    exit(2);	if( (acctFile = fopen(argv[optind], "a")) == NULL ) {	    fprintf(stderr, "ipf: can't open acct file: %s\n", argv[optind]);	    exit(2);	}	if( login )	    if( host )		fprintf(acctFile, "%d\t%s:%s\n", pageCount, host, login);	    else		fprintf(acctFile, "%d\t%s\n", pageCount, login);	exit(0);    }}/* * process one file */do_file(file)FILE *file;{# define  Buffsize	256    char buff[Buffsize];    char *ptr;    int len;    int bodyDepth;	/* how many bodies down we are */    register int bodyCount,	/* how many bodies we have seen so far */    		 val,    		 byte;		/* has to be "int" for stdio EOF detection */				/* stdio is a pile! */    int hlen;    hlen = strlen(IP_Header);    /* for error recovery */    if (setjmp(next_file) != 0)    {	return -1;    }    /* get the header */    for (hlen = 0, ptr = buff; hlen < Buffsize; hlen++)    {	if ((*ptr++ = getnoeofc(file)) == ' ')	    break;    }    *ptr = '\0';    /* check the validity of the header */    if (strcmp(buff, IP_Header) != 0)    {	fprintf(stderr, " (INVALID HEADER!)");    }    bodyDepth = 0;    bodyCount = 0;    /* main loop */    while ((byte = getc(file)) != EOF)    {	if ((byte & 0200) == 0)	{	    /* a short number */	    val = (byte << 8) + getnoeofc(file) - INTEGER_ZERO;	}	else	{	    /* something else */	    switch(byte >> 5)	    {		case (SHORT_OP >> 5):		    break;		case (LONG_OP >> 5):		    val = ((byte & 037) << 8) + getnoeofc(file);		    if( val == OP_beginBody )		    {			bodyDepth++;		    } 		    else if( val == OP_endBody )		    {			bodyDepth--;			/* is this a top level body? */			if( bodyDepth == 0 )			    bodyCount++;		    }		    break;		case (SHORT_SEQUENCE >> 5):		    len = getnoeofc(file);		    eatBytes(file, len);		    break;		case (LONG_SEQUENCE >> 5):		    len  =  getnoeofc(file) << 16;		    len += (getnoeofc(file) << 8);		    len += getnoeofc(file);		    eatBytes(file, len);		    break;	    }	}    }    return bodyCount - 1;	/* the preamble is an extra body */}/* * get a character */getnoeofc(file)FILE *file;{    register int val;#ifdef vax11c    val= getc(file);    if ( feof(file) )#else    if ((val = getc(file)) == EOF)#endif    {	fprintf(stderr, "Unexpected EOF!");	longjmp(next_file, 1);    }    return(val);}/* * read some bytes from the input stream */eatBytes(file, length)FILE *file;int length;{    register int count;    count = length;    while(count-- > 0)    {	(void) getnoeofc(file);    }}SHAR_EOF#	End of shell archiveexit 0

⌨️ 快捷键说明

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