DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T f

⟦e1fcc0f8c⟧ TextFile

    Length: 3675 (0xe5b)
    Types: TextFile
    Names: »filter.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦e83f91978⟧ »EurOpenD22/isode/osimis-2.0.tar.Z« 
        └─⟦d846658bd⟧ 
            └─⟦this⟧ »osimis/smap/filter.c« 

TextFile

/*
 * Copyright (c) 1988 University College London
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the Department of Computer Science, University College London.
 * The name of the University may not be used to
 * endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/* maintains a log of oncoming data from a special device */
/* spdevice stuff cribbed from link */

/* By Graham Knight,  0ctober 83
 * May 84    Modified to use libspdev routines
 * October 88 spdevices stuff removed
 */

#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>

extern int errno;

FILE *ioptr, *filefp;

char *crlf  = "\r\n";
char sep[] =  " <<==>> ";
char ifmt[] = "%d";
char df = 'd';

int bufflg = 1;
int teeflg = 0;

int endf();
int tee();
int flush();

#define SEPLEN ((sizeof sep) -1)
#define FLEN 10000L
#define LINELEN 80

long flen = FLEN;
int linelen = LINELEN;
int crmod = 0;
char obuf[BUFSIZ];

main(argc,argv)
	int argc;
	char **argv;{

	char buf[LINELEN], *cp;
	int n, part, rest;
	long space;

	setbuf(stderr, 0);

	argv++;
	argc--;

	while (*(cp = *argv) == '-'){
	    switch (*++cp){
		case 'u':
		    bufflg--;
		    break;
		case 'n':
		    argc--;
		    flen = (long)rnum(*++argv);
		    break;
		case 'l':
		    argc--;
		    linelen = rnum(*++argv);
		    if (linelen > LINELEN) linelen = LINELEN;
		    break;
	    }
	    argv++;
	    argc--;
	}

	if (argc != 1){
		fprintf(stderr,"useage: record [-u] [-n filelen] [-l \
linelen] <logname>\n");
		exit();
	}
/*
	signal(SIGINT, SIG_IGN);
*/
	signal(SIGILL, flush);
	signal(SIGTRAP, tee);


	if ((filefp = fopen(*argv, "w")) == NULL)
		fprintf(stderr, "record: can't open %s\n",*argv);

	space = flen;

	for (;;){
		fwrite(sep, SEPLEN, 1, filefp);
		if (bufflg == 0) fflush(filefp);
		fseek(filefp,-(long)(SEPLEN),1);
		if ((n = fread(buf, 1, linelen, stdin)) == NULL){
		    if (ferror(stdin)){
			if (errno == EINTR) continue;
			perror("record");
			endf();
		    }
		    if (feof(stdin)){
			fprintf(stderr,
				"record: end of file on input\n");
			endf();
		    }
		    fprintf(stderr, "record: unexplained NULL return\n");
		    endf();
		}

		part = ((long)n < space) ? n : (int)space;
		twrite(buf, 1, part, filefp);
		if ((space -= (long)part) == 0L){
			fseek (filefp,(long)0,0);
			if (rest = n-part) twrite(&buf[part], 1,
							rest, filefp);
			space = flen - (long)rest;
		}

	}
}

twrite(bufp, size, nitems, ioptr)
    char *bufp;
    int size, nitems;
    FILE *ioptr;{
	static int i=0;

	fwrite(bufp, size, nitems, ioptr);
	if (bufflg == 0) fflush(filefp);
	if (teeflg) {
	    fwrite(bufp, size, nitems, stdout);
	    fflush(stdout);
	}
}

flush(){
    signal(SIGILL, flush);
    fflush(filefp);
}

tee(){
    signal(SIGTRAP, tee);
    teeflg = 1 - teeflg;
}

endf(){

	fclose(filefp);

	exit();
}

rnum(cp)
register char *cp;
{
	int i;

	if (*cp == '0'){
		switch (*(cp+1) & ~0x20){
		case 'X':
			ifmt[1] = 'x';
			cp += 2;
			break;
		case '\0':
			ifmt[1] = 'd';
			break;
		default:
			ifmt[1] = 'o';
			cp++;
			break;
		}
	}
	else ifmt[1] = df;
	sscanf(cp,ifmt,&i);
	return(i);
}