#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 8_9a1.h 8_9a2.c 8_9a3.c 8_9a4.c 8_9a5.c 8_9b1.h 8_9b2.c 8_9b3.c 8_9b4.c 8_9b5.c 8_9c1.h 8_9c2.c 8_9c3.c 8_9c4.c 8_9c5.c 8_9tst.c makefile tst.cmp tst.data tst.save tst2.cmp # # To extract the files from this shell archive file simply # create a directory for this file, move the archive file # to it and enter the command # # sh filename # # The files will be extracted automatically. # Note: Do not use csh. # # Archive created: Mon Jul 30 23:13:55 EDT 1990 # echo x - 8_9a1.h sed 's/^X//' > 8_9a1.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ class eFILE { long fileoffset; FILE *fp; eFILE() { }; public: friend eFILE *efopen(char *file); friend void efclose(eFILE *efp); friend int egetc(eFILE *efp, long offset); friend int eputc(eFILE *efp, long offset, int newc); }; !EOF! ls -l 8_9a1.h echo x - 8_9a2.c sed 's/^X//' > 8_9a2.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ eFILE *efopen(char *file) { FILE *fp = fopen(file, "r+"); if (!fp) return 0; eFILE *e = new eFILE; e->fp = fp; e->fileoffset = 0; return e; } !EOF! ls -l 8_9a2.c echo x - 8_9a3.c sed 's/^X//' > 8_9a3.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ void efclose(eFILE *efp) { if (efp && efp->fp) fclose(efp->fp); delete efp; } !EOF! ls -l 8_9a3.c echo x - 8_9a4.c sed 's/^X//' > 8_9a4.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ int egetc(eFILE *efp, long offset) { if (!efp || !efp->fp) return EOF; if (offset != efp->fileoffset) if (fseek(efp->fp, offset, 0)) return EOF; int c = getc(efp->fp); if (c == EOF) efp->fileoffset = offset; else efp->fileoffset = offset + 1; return c; } !EOF! ls -l 8_9a4.c echo x - 8_9a5.c sed 's/^X//' > 8_9a5.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ int eputc(eFILE *efp, long offset, int newc) { if (!efp || !efp->fp) return EOF; if (offset != efp->fileoffset) if (fseek(efp->fp, offset, 0)) return EOF; int ret = putc(newc, efp->fp); if (ret == EOF) efp->fileoffset = offset; else efp->fileoffset = offset + 1; return ret; } !EOF! ls -l 8_9a5.c echo x - 8_9b1.h sed 's/^X//' > 8_9b1.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ class randomloc { eFILE *efp; long thisoffset; public: randomloc(eFILE*, long); operator int(); randomloc operator=(int newc); randomloc operator=(randomloc r); }; !EOF! ls -l 8_9b1.h echo x - 8_9b2.c sed 's/^X//' > 8_9b2.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ randomloc::randomloc(eFILE *rfp, long offset) { efp = rfp; thisoffset = offset; } !EOF! ls -l 8_9b2.c echo x - 8_9b3.c sed 's/^X//' > 8_9b3.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ randomloc::operator int() { return egetc(efp, thisoffset); } !EOF! ls -l 8_9b3.c echo x - 8_9b4.c sed 's/^X//' > 8_9b4.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ randomloc randomloc::operator=(int newc) { (void) eputc(efp, thisoffset, newc); return *this; } !EOF! ls -l 8_9b4.c echo x - 8_9b5.c sed 's/^X//' > 8_9b5.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ randomloc randomloc::operator=(randomloc r) { return (*this = (int) r); } !EOF! ls -l 8_9b5.c echo x - 8_9c1.h sed 's/^X//' > 8_9c1.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ class random { eFILE *rfp; public: random(char *filename); ~random(); int openedokay(); randomloc operator[](long offset); }; !EOF! ls -l 8_9c1.h echo x - 8_9c2.c sed 's/^X//' > 8_9c2.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ random::random(char *filename) { rfp = efopen(filename); } !EOF! ls -l 8_9c2.c echo x - 8_9c3.c sed 's/^X//' > 8_9c3.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ random::~random() { efclose(rfp); } !EOF! ls -l 8_9c3.c echo x - 8_9c4.c sed 's/^X//' > 8_9c4.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ int random::openedokay() { return rfp != 0; } !EOF! ls -l 8_9c4.c echo x - 8_9c5.c sed 's/^X//' > 8_9c5.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ randomloc random::operator[](long offset) { randomloc ret(rfp, offset); return ret; } !EOF! ls -l 8_9c5.c echo x - 8_9tst.c sed 's/^X//' > 8_9tst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include #include #include "8_9a1.h" /* class eFILE */ #include "8_9a2.c" /* eFILE *efopen(char*) */ #include "8_9a3.c" /* efclose(eFILE*) */ #include "8_9a4.c" /* int egetc(eFILE*, long) */ #include "8_9a5.c" /* int eputc(eFILE*, long, int) */ #include "8_9b1.h" /* class randomloc */ #include "8_9b2.c" /* randomloc::randomloc */ #include "8_9b3.c" /* randomloc::operator int() */ #include "8_9b4.c" /* randomloc operator=(randomloc, int) */ #include "8_9b5.c" /* randomloc operator=(randomloc, randomloc) */ #include "8_9c1.h" /* class random */ #include "8_9c2.c" /* random::random() */ #include "8_9c3.c" /* random::~random() */ #include "8_9c4.c" /* int random::openedokay() */ #include "8_9c5.c" /* randomloc random::operator[]() */ int main(int, char**) { random x("tst.data"); int i = x[3]; cout << "x[3] = " << i; if (isprint(i)) cout << ", " << chr(i); cout << "\n"; if ((int)x[2]) cout << "if x[2] passed\n"; else cout << "if x[2] failed\n"; x[1] = '3'; cout << "assigned x[1] <- '3'\n"; x[0] = x[9]; cout << "assigned x[0] <- x[8]\n"; return 0; } !EOF! ls -l 8_9tst.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../../CC all: 8_9tst 8_9tst: 8_9a1.h 8_9b1.h 8_9c1.h 8_9a2.c 8_9a3.c 8_9a4.c 8_9a5.c 8_9b2.c 8_9b3.c 8_9b4.c 8_9b5.c 8_9c2.c 8_9c3.c 8_9c4.c 8_9c5.c 8_9tst.c $(CC) 8_9tst.c -o 8_9tst CMP= tst.cmp tst2.cmp OUT= tst.out tst.out: 8_9tst tst.data cp tst.save tst.data 8_9tst > tst.out test: $(CMP) $(OUT) cmp tst.out tst.cmp cmp tst.data tst2.cmp @echo test done !EOF! ls -l makefile echo x - tst.cmp sed 's/^X//' > tst.cmp << '!EOF!' x[3] = 116, t if x[2] passed assigned x[1] <- '3' assigned x[0] <- x[8] !EOF! ls -l tst.cmp echo x - tst.data sed 's/^X//' > tst.data << '!EOF!' o3ot::0:root other::1: bin::2:root,bin,daemon sys::3:root,bin,sys,adm adm::4:root,adm,daemon uucp::5:root,uucp mail::6:root daemon::12:root,daemon docx::21:pcor,russak,mds,dsl,jeremy,bwp,hansen,coleman,chu,jack guest::22: !EOF! ls -l tst.data echo x - tst.save sed 's/^X//' > tst.save << '!EOF!' root::0:root other::1: bin::2:root,bin,daemon sys::3:root,bin,sys,adm adm::4:root,adm,daemon uucp::5:root,uucp mail::6:root daemon::12:root,daemon docx::21:pcor,russak,mds,dsl,jeremy,bwp,hansen,coleman,chu,jack guest::22: !EOF! ls -l tst.save echo x - tst2.cmp sed 's/^X//' > tst2.cmp << '!EOF!' o3ot::0:root other::1: bin::2:root,bin,daemon sys::3:root,bin,sys,adm adm::4:root,adm,daemon uucp::5:root,uucp mail::6:root daemon::12:root,daemon docx::21:pcor,russak,mds,dsl,jeremy,bwp,hansen,coleman,chu,jack guest::22: !EOF! ls -l tst2.cmp # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0