#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 8_10a1.h 8_10a4.c 8_10a5.c 8_10b1.h 8_10b2.c 8_10b3.c 8_10b4.c 8_10b5.c 8_10c1.h 8_10c2.c 8_10c3.c 8_10c4.c 8_10c5.c 8_10tst.c makefile pr.c 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:14:06 EDT 1990 # echo x - 8_10a1.h sed 's/^X//' > 8_10a1.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 egetobj(eFILE *efp, long offset, void *obj, unsigned szobj); friend int eputobj(eFILE *efp, long offset, void *obj, unsigned szobj); }; !EOF! ls -l 8_10a1.h echo x - 8_10a4.c sed 's/^X//' > 8_10a4.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ int egetobj(eFILE *efp, long offset, void *obj, unsigned szobj) { if (!efp || !efp->fp) return 0; if (offset != efp->fileoffset) if (fseek(efp->fp, offset * szobj, 0)) return 0; int ret = fread((char*)obj, szobj, 1, efp->fp); if (ret != 1) efp->fileoffset = offset; else efp->fileoffset = offset + 1; return ret; } !EOF! ls -l 8_10a4.c echo x - 8_10a5.c sed 's/^X//' > 8_10a5.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ int eputobj(eFILE *efp, long offset, void *obj, unsigned szobj) { if (!efp || !efp->fp) return 0; if (offset != efp->fileoffset) if (fseek(efp->fp, offset * szobj, 0)) return 0; int ret = fwrite((char*)obj, szobj, 1, efp->fp); if (ret != 1) efp->fileoffset = offset; else efp->fileoffset = offset + 1; return ret; } !EOF! ls -l 8_10a5.c echo x - 8_10b1.h sed 's/^X//' > 8_10b1.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ class randomOBJ; class OBJrandomloc { randomOBJ *rOBJ; long thisoffset; public: OBJrandomloc(randomOBJ*, long); operator OBJ(); OBJrandomloc operator=(OBJ newobj); OBJrandomloc operator=(OBJrandomloc r); }; !EOF! ls -l 8_10b1.h echo x - 8_10b2.c sed 's/^X//' > 8_10b2.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ OBJrandomloc::OBJrandomloc(randomOBJ *robj, long offset) { rOBJ = robj; thisoffset = offset; } !EOF! ls -l 8_10b2.c echo x - 8_10b3.c sed 's/^X//' > 8_10b3.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ OBJrandomloc::operator OBJ() { OBJ x; if (!egetobj(rOBJ->rfp, thisoffset, &x, sizeof x)) if (rOBJ->rdrfnc) (*rOBJ->rdrfnc)(&x); return x; } !EOF! ls -l 8_10b3.c echo x - 8_10b4.c sed 's/^X//' > 8_10b4.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ OBJrandomloc OBJrandomloc::operator=(OBJ newobj) { if (!eputobj(rOBJ->rfp, thisoffset, &newobj, sizeof newobj)) if (rOBJ->wtrfnc) (*rOBJ->wtrfnc)(&newobj); return *this; } !EOF! ls -l 8_10b4.c echo x - 8_10b5.c sed 's/^X//' > 8_10b5.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ OBJrandomloc OBJrandomloc::operator=(OBJrandomloc r) { return (*this = (OBJ) r); } !EOF! ls -l 8_10b5.c echo x - 8_10c1.h sed 's/^X//' > 8_10c1.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ class randomOBJ { eFILE *rfp; void (*rdrfnc)(OBJ *); void (*wtrfnc)(OBJ *); friend OBJrandomloc; OBJrandomloc operator=(OBJ newobj); public: randomOBJ(char *filename, void (*)(OBJ*) = 0, void (*)(OBJ*) = 0); ~randomOBJ(); int openedokay(); OBJrandomloc operator[](long offset); }; !EOF! ls -l 8_10c1.h echo x - 8_10c2.c sed 's/^X//' > 8_10c2.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ randomOBJ::randomOBJ(char *filename, void (*rfnc)(OBJ*), void (*wfnc)(OBJ*)) { rfp = efopen(filename); rdrfnc = rfnc; wtrfnc = wfnc; } !EOF! ls -l 8_10c2.c echo x - 8_10c3.c sed 's/^X//' > 8_10c3.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ randomOBJ::~randomOBJ() { efclose(rfp); } !EOF! ls -l 8_10c3.c echo x - 8_10c4.c sed 's/^X//' > 8_10c4.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ int randomOBJ::openedokay() { return rfp != 0; } !EOF! ls -l 8_10c4.c echo x - 8_10c5.c sed 's/^X//' > 8_10c5.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ OBJrandomloc randomOBJ::operator[](long offset) { OBJrandomloc ret(this, offset); return ret; } !EOF! ls -l 8_10c5.c echo x - 8_10tst.c sed 's/^X//' > 8_10tst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include #include struct OBJ { char x[4]; }; #include "8_10a1.h" /* class eFILE */ #include "8_10b1.h" /* class OBJrandomloc */ #include "8_10c1.h" /* class randomOBJ */ #include "../8.9dir/8_9a2.c" /* eFILE *efopen(char*) */ #include "../8.9dir/8_9a3.c" /* efclose(eFILE*) */ #include "8_10a4.c" /* egetobj() */ #include "8_10a5.c" /* OBJrandomloc operator=(OBJrandomloc,OBJrandomloc) */ #include "8_10b2.c" /* OBJrandomloc::OBJrandomloc() */ #include "8_10b3.c" /* OBJrandomloc::operator OBJ() */ #include "8_10b4.c" /* OBJrandomloc operator=(OBJrandomloc,OBJ) */ #include "8_10b5.c" /* OBJrandomloc operator=(OBJrandomloc,OBJrandomloc) */ #include "8_10c2.c" /* randomOBJ::randomOBJ() */ #include "8_10c3.c" /* randomOBJ::~randomOBJ() */ #include "8_10c4.c" /* randomOBJ::openedokay() */ #include "8_10c5.c" /* OBJrandomloc randomOBJ::operator[]() */ #define XXXXOBJ OBJ #include "pr.c" int main(int, char**) { randomOBJ x("tst.data"); OBJ i = x[3]; pr("x[3] = ", i); i = x[2]; pr("x[2] = ", i); i.x[0] = '3'; i.x[1] = ';'; pr("i = ", i); x[1] = i; cout << "assigned x[1] <- i('3;')\n"; x[0] = x[8]; cout << "assigned x[0] <- x[8]\n"; i = x[8]; pr("x[8] = ", i); i = x[0]; pr("x[0] = ", i); return 0; } !EOF! ls -l 8_10tst.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../../CC CFLAGS= all: 8_10tst 8_10tst: 8_10tst.c 8_10a1.h 8_10b1.h 8_10c1.h \ ../8.9dir/8_9a2.c ../8.9dir/8_9a3.c 8_10a4.c 8_10a5.c \ 8_10b2.c 8_10b3.c 8_10b4.c 8_10b5.c 8_10c2.c 8_10c3.c \ 8_10c4.c 8_10c5.c pr.c $(CC) $(CFLAGS) 8_10tst.c -o 8_10tst CMP= tst.cmp tst2.cmp OUT= tst.out tst.out: 8_10tst tst.save cp tst.save tst.data 8_10tst > tst.out test: $(CMP) $(OUT) cmp tst.out tst.cmp cmp tst.data tst2.cmp @echo test done !EOF! ls -l makefile echo x - pr.c sed 's/^X//' > pr.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ void pr(char* desc, XXXXOBJ i) { cout << desc; for (int j = 0; j < sizeof(XXXXOBJ)-1; j++) { cout << int(i.x[j]); if (isprint(i.x[j])) cout << "(" << chr(i.x[j]) << ")"; cout << ","; } cout << int(i.x[j]); if (isprint(i.x[j])) cout << "(" << chr(i.x[j]) << ")"; cout << "\n"; } !EOF! ls -l pr.c echo x - tst.cmp sed 's/^X//' > tst.cmp << '!EOF!' x[3] = 10,111(o),116(t),104(h) x[2] = 114(r),111(o),111(o),116(t) i = 51(3),59(;),111(o),116(t) assigned x[1] <- i('3;') assigned x[0] <- x[8] x[8] = 111(o),116(t),44(,),98(b) x[0] = 111(o),116(t),44(,),98(b) !EOF! ls -l tst.cmp echo x - tst.data sed 's/^X//' > tst.data << '!EOF!' ot,b3;otroot 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!' ot,b3;otroot 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