#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1997-03-17 10:32 MET by <john@pc.xs4all.nl>.
# Source directory was `/home/john/c'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   2079 -rw-r--r-- mmapme.c
#    360 -rwxr-xr-x mmap-test
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh02627; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= mmapme.c ==============
if test -f 'mmapme.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'mmapme.c' '(file already exists)'
else
  $echo 'x -' extracting 'mmapme.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'mmapme.c' &&
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
X
#define USAGE "\
Usage:\n\
\n\
mmapme [-p] filename\n"
X
extern int optind;
X
int main(int argc, char** argv) {
X    int fd;
X    char* p;
X    char* shm;
X    struct stat st;
X    int size, pagesize;
X    char line[80];
X    char prevline[80];
X    char* c;
X    int i, j, sup, previ;
X    int adjust = 0;
X
X    while ( (i = getopt(argc, argv, "p")) != EOF ) {
X	if ( i == 'p' ) {
X	    adjust++;
X	}
X	else {
X	    fprintf(stderr, USAGE);
X	    exit(1);
X	}
X    }
X    if ( optind != argc - 1 ) {
X	fprintf(stderr, USAGE);
X	exit(1);
X    }
X    if ( (fd = open(argv[optind], O_RDONLY)) == -1 ) {
X	perror("open");
X	exit(1);
X    }
X    if ( fstat(fd, &st) ) {
X	perror("stat");
X	exit(1);
X    }
X    size = st.st_size;
X    if ( adjust ) {
#ifdef _SC_PAGE_SIZE
X	pagesize = sysconf(_SC_PAGE_SIZE);
#else
# ifdef _SC_PAGESIZE
X	pagesize = sysconf(_SC_PAGESIZE);
# else
X	pagesize = getpagesize();
# endif
#endif
X	size = (size + pagesize - 1) & ~(pagesize - 1);
X    }
X    if ( (shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0))
X          == (void*) -1 ) {
X	perror("mmap");
X	exit(1);
X    }
X    prevline[0] = '\0';
X    sup = 0;
X    p = shm;
X    for (i = 0; i < st.st_size; i += 16 ) {
X	c = line;
X	for (j = i; j < i+16 && j < st.st_size; j++) {
X	    sprintf(c, "%02X ", *p++);
X	    c += 3;
X	}
X	if ( !strcmp(prevline, line) ) {
X	    previ = i;
X	    sup++;
X	    continue;
X	}
X	if ( sup == 1 ) {
X	    printf("%08X %s\n", previ, prevline);
X	    sup = 0;
X	}
X	else if ( sup == 2 ) {
X	    printf("%08X %s\n%08X %s\n", previ - 16, prevline, previ, prevline);
X	    sup = 0;
X	}
X	else if ( sup > 2 ) {
X	    printf("... %d lines ...\n%08X %s\n", sup - 1, previ, prevline);
X	    sup = 0;
X	}
X	printf("%08X %s\n", i, line);
X	strcpy(prevline, line);
X	previ = i;
X    }
X    if ( sup == 1 ) {
X	printf("%08X %s\n", previ, prevline);
X    }
X    else if ( sup > 1 ) {
X	printf("... %d lines ...\n%08X %s\n", sup - 1, previ, prevline);
X    }
X    sleep(60);
X    munmap(shm, size);
X    close(fd);
X    return(0);
}
SHAR_EOF
  $shar_touch -am 0317101297 'mmapme.c' &&
  chmod 0644 'mmapme.c' ||
  $echo 'restore of' 'mmapme.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'mmapme.c:' 'MD5 check failed'
31bdaf5e2c949e4659001315832adbb2  mmapme.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'mmapme.c'`"
    test 2079 -eq "$shar_count" ||
    $echo 'mmapme.c:' 'original size' '2079,' 'current size' "$shar_count!"
  fi
fi
# ============= mmap-test ==============
if test -f 'mmap-test' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'mmap-test' '(file already exists)'
else
  $echo 'x -' extracting 'mmap-test' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'mmap-test' &&
#!/bin/bash
X
echo -n 1111111111111111111111111111111111111111 > 40
cat 40 40 40 40 40 40 > 240
cat 240 240 240 240 40 > 1k
cat 1k 1k 1k 1k 1k > 5k
rm 40 240
cp 5k testfile
echo 1
X./mmapme $* testfile &
sleep 5
echo 1.5
cat 1k >> testfile
echo 2
X./mmapme $* testfile &
sleep 5
echo 2.5
cat 5k >> testfile
echo 3
X./mmapme $* testfile &
sleep 2
rm 1k 5k testfile
SHAR_EOF
  $shar_touch -am 0217120797 'mmap-test' &&
  chmod 0755 'mmap-test' ||
  $echo 'restore of' 'mmap-test' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'mmap-test:' 'MD5 check failed'
204a9c56650abab19f4f9d1e5012f401  mmap-test
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'mmap-test'`"
    test 360 -eq "$shar_count" ||
    $echo 'mmap-test:' 'original size' '360,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh02627
exit 0
