CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Fri, 18 Jul 2025 00:45:02 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20090210090515
location: https://web.archive.org/web/20090210090515/https://examples.oreilly.com/upt2/split/hgrep.shar
server-timing: captures_list;dur=2.287595, exclusion.robots;dur=0.025602, exclusion.robots.policy;dur=0.011549, esindex;dur=0.012958, cdx.remote;dur=10.345756, LoadShardBlock;dur=210.934547, PetaboxLoader3.datanode;dur=147.922970
x-app-server: wwwb-app212
x-ts: 302
x-tr: 248
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app212; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Fri, 18 Jul 2025 00:45:02 GMT
content-type: application/x-shar
content-length: 7276
x-archive-orig-date: Tue, 10 Feb 2009 09:05:15 GMT
x-archive-orig-server: Apache
x-archive-orig-last-modified: Mon, 31 Mar 2008 18:10:12 GMT
x-archive-orig-etag: "2272b7-1c6c-90194900"
x-archive-orig-accept-ranges: bytes
x-archive-orig-content-length: 7276
x-archive-orig-connection: close
cache-control: max-age=1800
x-archive-guessed-content-type: application/x-shar
x-archive-guessed-charset: utf-8
memento-datetime: Tue, 10 Feb 2009 09:05:15 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Wed, 19 Jun 2002 01:56:54 GMT", ; rel="prev memento"; datetime="Wed, 18 Oct 2006 00:09:31 GMT", ; rel="memento"; datetime="Tue, 10 Feb 2009 09:05:15 GMT", ; rel="next memento"; datetime="Wed, 30 Sep 2015 16:40:03 GMT", ; rel="last memento"; datetime="Fri, 25 Mar 2016 03:26:47 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_8_20090210075601_crawl103-c/52_8_20090210084506_crawl100.arc.gz
server-timing: captures_list;dur=0.660921, exclusion.robots;dur=0.022987, exclusion.robots.policy;dur=0.009879, esindex;dur=0.013636, cdx.remote;dur=42.293986, LoadShardBlock;dur=279.453970, PetaboxLoader3.datanode;dur=110.636197, PetaboxLoader3.resolve;dur=218.517228, load_resource;dur=207.054177
x-app-server: wwwb-app212
x-ts: 200
x-tr: 555
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
accept-ranges: bytes
Subject: v16i072: Highlighting grep filter
Newsgroups: comp.sources.unix
Sender: sources
Approved: rsalz@uunet.UU.NET
Submitted-by: Jef Poskanzer
Posting-number: Volume 16, Issue 72
Archive-name: hgrep
[ Jef's two-line summary is 100% on-the-mark. In these days of huge
source postings to comp.sources.unix, let's not forget the little
tools and filters. --r$ ]
Hgrep is a trivial, but cute, front-end for grep. It takes the results of
the grep and highlights the word that was searched for.
#! /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:
# README
# Makefile
# hgrep.c
# hgrep.1
export PATH; PATH=/bin:$PATH
echo shar: extracting "'README'" '(578 characters)'
if test -f 'README'
then
echo shar: will not over-write existing file "'README'"
else
sed 's/^X//' << \SHAR_EOF > 'README'
X hgrep
X Distribution of 31oct87
X
XHgrep is a trivial, but cute, front-end for grep. It takes the results of
Xthe grep and highlights the word that was searched for.
X
XFiles in this distribution:
X
X README this
X Makefile guess
X hgrep.c source file
X hgrep.1 manual entry
X
XI've tested this stuff Suns and vaxen, but I'm sure bugs remain.
XFeedback is welcome - send bug reports, enhancements, checks, money
Xorders, etc. to the addresses below.
X
X Jef Poskanzer
X jef@rtsg.ee.lbl.gov
X {ucbvax, lll-crg, sun!pacbell, apple, hplabs}!well!pokey
SHAR_EOF
if test 578 -ne "`wc -c < 'README'`"
then
echo shar: error transmitting "'README'" '(should have been 578 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'Makefile'" '(319 characters)'
if test -f 'Makefile'
then
echo shar: will not over-write existing file "'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X# Makefile for hgrep
X
Xall: hgrep hgrep.cat
X
Xhgrep: hgrep.c
X cc -O -s hgrep.c -ltermcap -o hgrep
X
Xhgrep.cat: hgrep.1
X nroff -man hgrep.1 > hgrep.cat
X
Xclean:
X -rm -f hgrep hgrep.cat hgrep.shar
X
Xshar: hgrep.shar
X
Xhgrep.shar: README Makefile hgrep.c hgrep.1
X shar -v -c -p X README Makefile hgrep.c hgrep.1 > hgrep.shar
SHAR_EOF
if test 319 -ne "`wc -c < 'Makefile'`"
then
echo shar: error transmitting "'Makefile'" '(should have been 319 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'hgrep.c'" '(3599 characters)'
if test -f 'hgrep.c'
then
echo shar: will not over-write existing file "'hgrep.c'"
else
sed 's/^X//' << \SHAR_EOF > 'hgrep.c'
X/*
X** hgrep - a front end to grep that highlights the string found
X**
X** version of 23oct88
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation. This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include
X#include
X
X#define TBUFSIZE 1024
X#define BIGBUFSIZE 20000
X
Xextern char *getenv();
Xextern char *tgetstr();
Xvoid putch();
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X {
X char *term, *strptr, *soptr, *septr;
X int dumb = 0;
X int iflag = 0;
X char buf[TBUFSIZE];
X static char strbuf[TBUFSIZE];
X char bigbuf[BIGBUFSIZE];
X char *grepword = NULL;
X FILE *grepstream;
X int i, j, soon, somap[BIGBUFSIZE], grepwordlen;
X
X /* Initialize termcap stuff. */
X if ( ! isatty( fileno( stdout ) ) )
X dumb = 1;
X else
X {
X term = getenv( "TERM" );
X if ( term == 0 )
X dumb = 1;
X else if ( tgetent( buf, term ) <= 0 )
X dumb = 1;
X else
X {
X strptr = strbuf;
X soptr = tgetstr( "so", &strptr );
X septr = tgetstr( "se", &strptr );
X if ( soptr == NULL || septr == NULL )
X dumb = 1;
X }
X }
X
X /* Construct grep command. */
X strcpy( bigbuf, "grep" );
X for ( i = 1; i < argc; i++ )
X {
X strcat( bigbuf, " " );
X /* (Should do some kind of quoting here.) */
X strcat( bigbuf, argv[i] );
X
X /* Check for -i flag. */
X if ( argv[i][0] == '-' && strchr( argv[i], 'i' ) != NULL )
X iflag = 1;
X
X /* Save pointer to word we are grepping for - first non-flag arg. */
X if ( grepword == NULL && argv[i][0] != '-' )
X {
X grepword = argv[i];
X grepwordlen = strlen( grepword );
X }
X }
X
X /* Spawn a grep. */
X grepstream = popen( bigbuf, "r" );
X if ( grepstream == NULL )
X {
X fprintf( stderr, "%s: can't spawn grep\n", argv[0] );
X exit( 1 );
X }
X
X /* Now read and handle results of grep. */
X soon = 0;
X while ( fgets( bigbuf, BIGBUFSIZE, grepstream ) != NULL )
X {
X if ( dumb )
X fputs( bigbuf, stdout );
X else
X {
X /* Figure out what to highlight. This is fairly inefficient,
X ** but since we are operating on the output of grep and not
X ** the input, it's ok. */
X for ( i = 0; bigbuf[i] != '\0'; i++ )
X somap[i] = 0;
X for ( i = 0; bigbuf[i] != '\0'; i++ )
X if ( iflag )
X {
X if ( cistrncmp( &(bigbuf[i]), grepword, grepwordlen ) == 0 )
X for ( j = i; j < i + grepwordlen; j++ )
X somap[j] = 1;
X }
X else
X {
X if ( strncmp( &(bigbuf[i]), grepword, grepwordlen ) == 0 )
X for ( j = i; j < i + grepwordlen; j++ )
X somap[j] = 1;
X }
X
X /* And now do the highlighting. */
X for ( i = 0; bigbuf[i] != '\0'; i++ )
X {
X if ( somap[i] )
X {
X if ( ! soon )
X {
X tputs( soptr, 1, putch );
X soon = 1;
X }
X }
X else
X {
X if ( soon )
X {
X tputs( septr, 1, putch );
X soon = 0;
X }
X }
X putchar( bigbuf[i] );
X }
X }
X }
X
X /* Bye. */
X if ( soon )
X tputs( septr, 1, putch );
X exit( pclose( grepstream ) );
X }
X
Xvoid
Xputch( ch )
Xchar ch;
X {
X putchar( ch );
X }
X
X
X/* cistrncmp - case-insensitive version of strncmp */
X
X#include
X
Xcistrncmp( s1, s2, n )
Xchar *s1, *s2;
Xint n;
X {
X while ( --n >= 0 && (isupper(*s1)?tolower(*s1):*s1) == (isupper(*s2)?tolower(*s2++):*s2++) )
X if ( *s1++ == '\0' )
X return 0;
X return n < 0 ? 0 : *s1 - *--s2;
X }
SHAR_EOF
if test 3599 -ne "`wc -c < 'hgrep.c'`"
then
echo shar: error transmitting "'hgrep.c'" '(should have been 3599 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'hgrep.1'" '(348 characters)'
if test -f 'hgrep.1'
then
echo shar: will not over-write existing file "'hgrep.1'"
else
sed 's/^X//' << \SHAR_EOF > 'hgrep.1'
X.TH HGREP 1 "23 October 1988"
X.SH NAME
Xhgrep - highlight results of a grep
X.SH SYNOPSIS
Xhgrep
X.SH DESCRIPTION
X.I Hgrep
Xis a trivial, but cute, front-end for
X.I grep.
XIt takes the results of the grep and highlights the word that was
Xsearched for.
X.SH "SEE ALSO"
Xgrep(1)
X.SH BUGS
XMeta-characters are not handled. Quoting is not handled.
SHAR_EOF
if test 348 -ne "`wc -c < 'hgrep.1'`"
then
echo shar: error transmitting "'hgrep.1'" '(should have been 348 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0