#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 4_13.c error.c makefile tst.c tst0.cmp tst1.cmp tst2.cmp tst3.cmp tst4.cmp tst5.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:00:23 EDT 1990 # echo x - 4_13.c sed 's/^X//' > 4_13.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Error function. fmt is a printf-style format string. // The formatted message is written to the error // stream and then the function calls exit(1). #include #include extern void exit(int); void error(const char *fmt ...) { va_list ap; va_start(ap, fmt); char ch; // loop across format string while (ch = *fmt++) // output normal chars if (ch != '%') cerr.put(ch); else // found % sequence switch (ch = *fmt++) { // %% becomes a single % case '%': cerr.put('%'); break; // output string case 's': { char *s = va_arg(ap, char*); cerr << s; } break; // output decimal integer case 'd': { int s = va_arg(ap, int); cerr << s; } break; // output character case 'c': { int s = va_arg(ap, int); cerr.put(s); } break; default: cerr << "\nunknown % sequence: %" << chr(ch) << "\n"; break; } // all done va_end(ap); exit(1); } !EOF! ls -l 4_13.c echo x - error.c sed 's/^X//' > error.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Error function. fmt is a printf-style format string. // The formatted message is written to the error // stream and then the function calls exit(1). #include #include extern void exit(int); void error(const char *fmt ...) { va_list ap; va_start(ap, fmt); char ch; // loop across format string while (ch = *fmt++) // output normal chars if (ch != '%') cerr.put(ch); else // found % sequence switch (ch = *fmt++) { // %% becomes a single % case '%': cerr.put('%'); break; // output string case 's': { char *s = va_arg(ap, char*); cerr << s; } break; // output decimal integer case 'd': { int s = va_arg(ap, int); cerr << s; } break; // output character case 'c': { int s = va_arg(ap, int); cerr.put(s); } break; default: cerr << "\nunknown % sequence: %" << chr(ch) << "\n"; break; } // all done va_end(ap); exit(1); } !EOF! ls -l error.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../../CC all: tst tst: tst.o error.o $(CC) tst.o error.o -o tst error.o: error.c $(CC) -c error.c tst.o: tst.c $(CC) -c tst.c OUT= tst0.out tst1.out tst2.out tst3.out tst4.out tst5.out CMP= tst0.cmp tst1.cmp tst2.cmp tst3.cmp tst4.cmp tst5.cmp tst0.out: tst ; -./tst 2> tst0.out tst1.out: tst ; -./tst 1 2> tst1.out tst2.out: tst ; -./tst 2 2> tst2.out tst3.out: tst ; -./tst 3 2> tst3.out tst4.out: tst ; -./tst 4 2> tst4.out tst5.out: tst ; -./tst 5 2> tst5.out test: all $(OUT) $(CMP) cmp tst0.out tst0.cmp cmp tst1.out tst1.cmp cmp tst2.out tst2.cmp cmp tst3.out tst3.cmp cmp tst4.out tst4.cmp cmp tst5.out tst5.cmp echo tests done !EOF! ls -l makefile echo x - tst.c sed 's/^X//' > tst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include extern void error(const char *fmt ...); main(int argc, char **argv) { switch (argc > 1 ? atoi(argv[1]) : 0) { case 1: error("Usage: %s 1 2 3\n", argv[0]); break; case 2: error("this is a test!!!\n"); break; case 3: error("5=%d, 6=%o\n", 5, 6); break; case 4: error("5=%d, 6=%d\n", 5, 6); break; case 5: error("5=%d, 6=%d, 7=%d\n", 5, 6, 7); break; default: error("unknown case\n"); break; } return 0; } !EOF! ls -l tst.c echo x - tst0.cmp sed 's/^X//' > tst0.cmp << '!EOF!' unknown case !EOF! ls -l tst0.cmp echo x - tst1.cmp sed 's/^X//' > tst1.cmp << '!EOF!' Usage: ./tst 1 2 3 !EOF! ls -l tst1.cmp echo x - tst2.cmp sed 's/^X//' > tst2.cmp << '!EOF!' this is a test!!! !EOF! ls -l tst2.cmp echo x - tst3.cmp sed 's/^X//' > tst3.cmp << '!EOF!' 5=5, 6= unknown % sequence: %o !EOF! ls -l tst3.cmp echo x - tst4.cmp sed 's/^X//' > tst4.cmp << '!EOF!' 5=5, 6=6 !EOF! ls -l tst4.cmp echo x - tst5.cmp sed 's/^X//' > tst5.cmp << '!EOF!' 5=5, 6=6, 7=7 !EOF! ls -l tst5.cmp # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0