home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / lookup.c++ < prev    next >
SHell self-extracting ARchive  |  1989-03-04  |  10.3 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: SHell self-extracting ARchive (archive/shar).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert SHell self-extracting ARchive (archive/shar) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/329 Shell Archive Format default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 4e 65 77 73 67 72 6f 75 | 70 73 3a 20 63 6f 6d 70 |Newsgrou|ps: comp|
|00000010| 2e 73 6f 75 72 63 65 73 | 2e 6d 69 73 63 0a 46 72 |.sources|.misc.Fr|
|00000020| 6f 6d 3a 20 61 6c 6c 62 | 65 72 79 40 75 75 6e 65 |om: allb|ery@uune|
|00000030| 74 2e 55 55 2e 4e 45 54 | 20 28 42 72 61 6e 64 6f |t.UU.NET| (Brando|
|00000040| 6e 20 53 2e 20 41 6c 6c | 62 65 72 79 20 2d 20 63 |n S. All|bery - c|
|00000050| 6f 6d 70 2e 73 6f 75 72 | 63 65 73 2e 6d 69 73 63 |omp.sour|ces.misc|
|00000060| 29 0a 53 75 62 6a 65 63 | 74 3a 20 76 30 36 69 30 |).Subjec|t: v06i0|
|00000070| 34 33 3a 20 6c 6f 6f 6b | 75 70 20 2d 2d 20 6c 6f |43: look|up -- lo|
|00000080| 6f 6b 20 75 70 20 63 6f | 6d 6d 61 6e 64 73 20 69 |ok up co|mmands i|
|00000090| 6e 20 74 61 62 6c 65 0a | 4b 65 79 77 6f 72 64 73 |n table.|Keywords|
|000000a0| 3a 20 63 2b 2b 2c 20 6c | 6f 6f 6b 75 70 20 74 61 |: c++, l|ookup ta|
|000000b0| 62 6c 65 2c 20 6c 69 6e | 65 61 72 20 61 6e 64 20 |ble, lin|ear and |
|000000c0| 62 69 6e 61 72 79 20 73 | 65 61 72 63 68 0a 52 65 |binary s|earch.Re|
|000000d0| 70 6c 79 2d 54 6f 3a 20 | 67 65 61 63 21 72 61 65 |ply-To: |geac!rae|
|000000e0| 20 28 52 65 69 64 20 45 | 6c 6c 69 73 29 0a 4f 72 | (Reid E|llis).Or|
|000000f0| 67 61 6e 69 7a 61 74 69 | 6f 6e 3a 20 54 27 6e 69 |ganizati|on: T'ni|
|00000100| 72 20 53 6f 66 74 77 61 | 72 65 0a 0a 50 6f 73 74 |r Softwa|re..Post|
|00000110| 69 6e 67 2d 6e 75 6d 62 | 65 72 3a 20 56 6f 6c 75 |ing-numb|er: Volu|
|00000120| 6d 65 20 36 2c 20 49 73 | 73 75 65 20 34 33 0a 53 |me 6, Is|sue 43.S|
|00000130| 75 62 6d 69 74 74 65 64 | 2d 62 79 3a 20 72 61 65 |ubmitted|-by: rae|
|00000140| 40 62 2e 55 55 43 50 20 | 28 52 65 69 64 20 45 6c |@b.UUCP |(Reid El|
|00000150| 6c 69 73 29 0a 41 72 63 | 68 69 76 65 2d 6e 61 6d |lis).Arc|hive-nam|
|00000160| 65 3a 20 6c 6f 6f 6b 75 | 70 2e 63 2b 2b 0a 0a 0a |e: looku|p.c++...|
|00000170| 54 68 65 20 66 6f 6c 6c | 6f 77 69 6e 67 20 73 68 |The foll|owing sh|
|00000180| 61 72 20 69 6d 70 6c 65 | 6d 65 6e 74 73 20 61 20 |ar imple|ments a |
|00000190| 6c 6f 6f 6b 75 70 20 74 | 61 62 6c 65 20 69 6e 20 |lookup t|able in |
|000001a0| 43 2b 2b 2e 20 20 54 77 | 6f 20 61 6c 74 65 72 6e |C++. Tw|o altern|
|000001b0| 61 74 65 0a 61 6c 67 6f | 72 69 74 68 6d 73 20 61 |ate.algo|rithms a|
|000001c0| 72 65 20 70 72 65 73 65 | 6e 74 65 64 2c 20 62 69 |re prese|nted, bi|
|000001d0| 6e 61 72 79 20 61 6e 64 | 20 6c 69 6e 65 61 72 20 |nary and| linear |
|000001e0| 73 65 61 72 63 68 2c 20 | 69 6e 20 74 68 65 20 66 |search, |in the f|
|000001f0| 69 6c 65 73 20 6c 6f 6f | 6b 75 70 2e 63 0a 61 6e |iles loo|kup.c.an|
|00000200| 64 20 6c 6f 6f 6b 75 70 | 32 2e 63 2c 20 72 65 73 |d lookup|2.c, res|
|00000210| 70 65 63 74 69 76 65 6c | 79 2e 20 20 53 65 65 20 |pectivel|y. See |
|00000220| 74 68 65 20 52 45 41 44 | 4d 45 20 66 69 6c 65 20 |the READ|ME file |
|00000230| 66 6f 72 20 6d 6f 72 65 | 20 64 65 74 61 69 6c 73 |for more| details|
|00000240| 2e 20 20 44 6f 6e 27 74 | 0a 77 6f 72 72 79 20 2d |. Don't|.worry -|
|00000250| 2d 20 74 68 65 72 65 27 | 73 20 61 6e 20 22 65 78 |- there'|s an "ex|
|00000260| 69 74 22 20 62 65 66 6f | 72 65 20 6d 79 20 2e 73 |it" befo|re my .s|
|00000270| 69 67 6e 61 74 75 72 65 | 2e 0a 0a 09 09 09 09 09 |ignature|........|
|00000280| 52 65 69 64 0a 0a 23 21 | 20 2f 62 69 6e 2f 73 68 |Reid..#!| /bin/sh|
|00000290| 0a 23 20 54 68 69 73 20 | 69 73 20 61 20 73 68 65 |.# This |is a she|
|000002a0| 6c 6c 20 61 72 63 68 69 | 76 65 2e 20 20 52 65 6d |ll archi|ve. Rem|
|000002b0| 6f 76 65 20 61 6e 79 74 | 68 69 6e 67 20 62 65 66 |ove anyt|hing bef|
|000002c0| 6f 72 65 20 74 68 69 73 | 20 6c 69 6e 65 2c 20 74 |ore this| line, t|
|000002d0| 68 65 6e 20 75 6e 70 61 | 63 6b 0a 23 20 69 74 20 |hen unpa|ck.# it |
|000002e0| 62 79 20 73 61 76 69 6e | 67 20 69 74 20 69 6e 74 |by savin|g it int|
|000002f0| 6f 20 61 20 66 69 6c 65 | 20 61 6e 64 20 74 79 70 |o a file| and typ|
|00000300| 69 6e 67 20 22 73 68 20 | 66 69 6c 65 22 2e 20 20 |ing "sh |file". |
|00000310| 54 6f 20 6f 76 65 72 77 | 72 69 74 65 20 65 78 69 |To overw|rite exi|
|00000320| 73 74 69 6e 67 0a 23 20 | 66 69 6c 65 73 2c 20 74 |sting.# |files, t|
|00000330| 79 70 65 20 22 73 68 20 | 66 69 6c 65 20 2d 63 22 |ype "sh |file -c"|
|00000340| 2e 20 20 59 6f 75 20 63 | 61 6e 20 61 6c 73 6f 20 |. You c|an also |
|00000350| 66 65 65 64 20 74 68 69 | 73 20 61 73 20 73 74 61 |feed thi|s as sta|
|00000360| 6e 64 61 72 64 20 69 6e | 70 75 74 20 76 69 61 0a |ndard in|put via.|
|00000370| 23 20 75 6e 73 68 61 72 | 2c 20 6f 72 20 62 79 20 |# unshar|, or by |
|00000380| 74 79 70 69 6e 67 20 22 | 73 68 20 3c 66 69 6c 65 |typing "|sh <file|
|00000390| 22 2c 20 65 2e 67 2e 2e | 20 20 49 66 20 74 68 69 |", e.g..| If thi|
|000003a0| 73 20 61 72 63 68 69 76 | 65 20 69 73 20 63 6f 6d |s archiv|e is com|
|000003b0| 70 6c 65 74 65 2c 20 79 | 6f 75 0a 23 20 77 69 6c |plete, y|ou.# wil|
|000003c0| 6c 20 73 65 65 20 74 68 | 65 20 66 6f 6c 6c 6f 77 |l see th|e follow|
|000003d0| 69 6e 67 20 6d 65 73 73 | 61 67 65 20 61 74 20 74 |ing mess|age at t|
|000003e0| 68 65 20 65 6e 64 3a 0a | 23 09 09 22 45 6e 64 20 |he end:.|#.."End |
|000003f0| 6f 66 20 73 68 65 6c 6c | 20 61 72 63 68 69 76 65 |of shell| archive|
|00000400| 2e 22 0a 23 20 43 6f 6e | 74 65 6e 74 73 3a 20 20 |.".# Con|tents: |
|00000410| 4d 61 6b 65 66 69 6c 65 | 20 52 45 41 44 4d 45 20 |Makefile| README |
|00000420| 6c 6f 6f 6b 75 70 2e 63 | 20 6c 6f 6f 6b 75 70 2e |lookup.c| lookup.|
|00000430| 68 20 6c 6f 6f 6b 75 70 | 32 2e 63 20 74 65 73 74 |h lookup|2.c test|
|00000440| 2e 63 0a 23 20 20 20 74 | 65 73 74 63 6d 64 2e 63 |.c.# t|estcmd.c|
|00000450| 20 74 65 73 74 68 65 6c | 70 2e 63 0a 23 20 57 72 | testhel|p.c.# Wr|
|00000460| 61 70 70 65 64 20 62 79 | 20 72 61 65 40 67 65 61 |apped by| rae@gea|
|00000470| 63 6c 69 62 20 6f 6e 20 | 54 75 65 20 46 65 62 20 |clib on |Tue Feb |
|00000480| 20 37 20 30 35 3a 33 37 | 3a 34 35 20 31 39 38 39 | 7 05:37|:45 1989|
|00000490| 0a 50 41 54 48 3d 2f 62 | 69 6e 3a 2f 75 73 72 2f |.PATH=/b|in:/usr/|
|000004a0| 62 69 6e 3a 2f 75 73 72 | 2f 75 63 62 20 3b 20 65 |bin:/usr|/ucb ; e|
|000004b0| 78 70 6f 72 74 20 50 41 | 54 48 0a 69 66 20 74 65 |xport PA|TH.if te|
|000004c0| 73 74 20 2d 66 20 4d 61 | 6b 65 66 69 6c 65 20 2d |st -f Ma|kefile -|
|000004d0| 61 20 22 24 7b 31 7d 22 | 20 21 3d 20 22 2d 63 22 |a "${1}"| != "-c"|
|000004e0| 20 3b 20 74 68 65 6e 20 | 0a 20 20 65 63 68 6f 20 | ; then |. echo |
|000004f0| 73 68 61 72 3a 20 57 69 | 6c 6c 20 6e 6f 74 20 6f |shar: Wi|ll not o|
|00000500| 76 65 72 2d 77 72 69 74 | 65 20 65 78 69 73 74 69 |ver-writ|e existi|
|00000510| 6e 67 20 66 69 6c 65 20 | 5c 22 4d 61 6b 65 66 69 |ng file |\"Makefi|
|00000520| 6c 65 5c 22 0a 65 6c 73 | 65 0a 65 63 68 6f 20 73 |le\".els|e.echo s|
|00000530| 68 61 72 3a 20 45 78 74 | 72 61 63 74 69 6e 67 20 |har: Ext|racting |
|00000540| 5c 22 4d 61 6b 65 66 69 | 6c 65 5c 22 20 5c 28 34 |\"Makefi|le\" \(4|
|00000550| 31 39 20 63 68 61 72 61 | 63 74 65 72 73 5c 29 0a |19 chara|cters\).|
|00000560| 73 65 64 20 22 73 2f 5e | 58 2f 2f 22 20 3e 4d 61 |sed "s/^|X//" >Ma|
|00000570| 6b 65 66 69 6c 65 20 3c | 3c 27 45 4e 44 5f 4f 46 |kefile <|<'END_OF|
|00000580| 5f 4d 61 6b 65 66 69 6c | 65 27 0a 58 43 43 20 3d |_Makefil|e'.XCC =|
|00000590| 20 43 43 20 2d 63 20 2d | 49 2f 75 73 72 2f 69 6e | CC -c -|I/usr/in|
|000005a0| 63 6c 75 64 65 2f 43 43 | 0a 58 4c 44 20 3d 20 43 |clude/CC|.XLD = C|
|000005b0| 43 0a 58 0a 58 2e 63 2e | 6f 3a 0a 58 09 24 28 43 |C.X.X.c.|o:.X.$(C|
|000005c0| 43 29 20 24 28 43 46 4c | 41 47 53 29 20 24 3c 0a |C) $(CFL|AGS) $<.|
|000005d0| 58 0a 58 23 20 6c 6f 6f | 6b 75 70 32 20 64 6f 65 |X.X# loo|kup2 doe|
|000005e0| 73 20 61 20 6c 69 6e 65 | 61 72 20 73 65 61 72 63 |s a line|ar searc|
|000005f0| 68 20 2d 2d 20 67 6f 6f | 64 20 66 6f 72 20 75 6e |h -- goo|d for un|
|00000600| 73 6f 72 74 65 64 20 74 | 61 62 6c 65 0a 58 23 20 |sorted t|able.X# |
|00000610| 6c 6f 6f 6b 75 70 20 20 | 64 6f 65 73 20 61 20 62 |lookup |does a b|
|00000620| 69 6e 61 72 79 20 73 65 | 61 72 63 68 20 2d 2d 20 |inary se|arch -- |
|00000630| 67 6f 6f 64 20 66 6f 72 | 20 61 20 73 6f 72 74 65 |good for| a sorte|
|00000640| 64 20 74 61 62 6c 65 0a | 58 4f 42 4a 20 3d 20 74 |d table.|XOBJ = t|
|00000650| 65 73 74 2e 6f 20 6c 6f | 6f 6b 75 70 32 2e 6f 20 |est.o lo|okup2.o |
|00000660| 74 65 73 74 63 6d 64 2e | 6f 20 74 65 73 74 68 65 |testcmd.|o testhe|
|00000670| 6c 70 2e 6f 0a 58 23 4f | 42 4a 20 3d 20 74 65 73 |lp.o.X#O|BJ = tes|
|00000680| 74 2e 6f 20 6c 6f 6f 6b | 75 70 2e 6f 20 74 65 73 |t.o look|up.o tes|
|00000690| 74 63 6d 64 2e 6f 20 74 | 65 73 74 68 65 6c 70 2e |tcmd.o t|esthelp.|
|000006a0| 6f 0a 58 54 41 52 47 20 | 3d 20 74 74 0a 58 0a 58 |o.XTARG |= tt.X.X|
|000006b0| 24 28 54 41 52 47 29 3a | 20 24 28 4f 42 4a 29 0a |$(TARG):| $(OBJ).|
|000006c0| 58 09 24 28 4c 44 29 20 | 2d 6f 20 24 28 54 41 52 |X.$(LD) |-o $(TAR|
|000006d0| 47 29 20 24 28 4f 42 4a | 29 20 24 28 4c 44 46 4c |G) $(OBJ|) $(LDFL|
|000006e0| 41 47 53 29 0a 58 09 40 | 73 74 72 69 70 20 24 28 |AGS).X.@|strip $(|
|000006f0| 54 41 52 47 29 0a 58 0a | 58 6c 6f 6f 6b 75 70 2e |TARG).X.|Xlookup.|
|00000700| 6f 20 6c 6f 6f 6b 75 70 | 32 2e 6f 20 3a 20 6c 6f |o lookup|2.o : lo|
|00000710| 6f 6b 75 70 2e 68 0a 58 | 74 65 73 74 2e 6f 20 3a |okup.h.X|test.o :|
|00000720| 20 6c 6f 6f 6b 75 70 2e | 68 0a 58 74 65 73 74 68 | lookup.|h.Xtesth|
|00000730| 65 6c 70 2e 6f 20 3a 20 | 6c 6f 6f 6b 75 70 2e 68 |elp.o : |lookup.h|
|00000740| 0a 45 4e 44 5f 4f 46 5f | 4d 61 6b 65 66 69 6c 65 |.END_OF_|Makefile|
|00000750| 0a 69 66 20 74 65 73 74 | 20 34 31 39 20 2d 6e 65 |.if test| 419 -ne|
|00000760| 20 60 77 63 20 2d 63 20 | 3c 4d 61 6b 65 66 69 6c | `wc -c |<Makefil|
|00000770| 65 60 3b 20 74 68 65 6e | 0a 20 20 20 20 65 63 68 |e`; then|. ech|
|00000780| 6f 20 73 68 61 72 3a 20 | 5c 22 4d 61 6b 65 66 69 |o shar: |\"Makefi|
|00000790| 6c 65 5c 22 20 75 6e 70 | 61 63 6b 65 64 20 77 69 |le\" unp|acked wi|
|000007a0| 74 68 20 77 72 6f 6e 67 | 20 73 69 7a 65 21 0a 66 |th wrong| size!.f|
|000007b0| 69 0a 23 20 65 6e 64 20 | 6f 66 20 6f 76 65 72 77 |i.# end |of overw|
|000007c0| 72 69 74 69 6e 67 20 63 | 68 65 63 6b 0a 66 69 0a |riting c|heck.fi.|
|000007d0| 69 66 20 74 65 73 74 20 | 2d 66 20 52 45 41 44 4d |if test |-f READM|
|000007e0| 45 20 2d 61 20 22 24 7b | 31 7d 22 20 21 3d 20 22 |E -a "${|1}" != "|
|000007f0| 2d 63 22 20 3b 20 74 68 | 65 6e 20 0a 20 20 65 63 |-c" ; th|en . ec|
|00000800| 68 6f 20 73 68 61 72 3a | 20 57 69 6c 6c 20 6e 6f |ho shar:| Will no|
|00000810| 74 20 6f 76 65 72 2d 77 | 72 69 74 65 20 65 78 69 |t over-w|rite exi|
|00000820| 73 74 69 6e 67 20 66 69 | 6c 65 20 5c 22 52 45 41 |sting fi|le \"REA|
|00000830| 44 4d 45 5c 22 0a 65 6c | 73 65 0a 65 63 68 6f 20 |DME\".el|se.echo |
|00000840| 73 68 61 72 3a 20 45 78 | 74 72 61 63 74 69 6e 67 |shar: Ex|tracting|
|00000850| 20 5c 22 52 45 41 44 4d | 45 5c 22 20 5c 28 32 38 | \"READM|E\" \(28|
|00000860| 32 37 20 63 68 61 72 61 | 63 74 65 72 73 5c 29 0a |27 chara|cters\).|
|00000870| 73 65 64 20 22 73 2f 5e | 58 2f 2f 22 20 3e 52 45 |sed "s/^|X//" >RE|
|00000880| 41 44 4d 45 20 3c 3c 27 | 45 4e 44 5f 4f 46 5f 52 |ADME <<'|END_OF_R|
|00000890| 45 41 44 4d 45 27 0a 58 | 44 45 53 43 52 49 50 54 |EADME'.X|DESCRIPT|
|000008a0| 49 4f 4e 0a 58 0a 58 55 | 73 69 6e 67 20 74 68 65 |ION.X.XU|sing the|
|000008b0| 20 66 69 6c 65 73 20 6c | 6f 6f 6b 75 70 2e 63 20 | files l|ookup.c |
|000008c0| 5b 6f 72 20 6c 6f 6f 6b | 75 70 32 2e 63 5d 20 61 |[or look|up2.c] a|
|000008d0| 6e 64 20 6c 6f 6f 6b 75 | 70 2e 68 2c 20 79 6f 75 |nd looku|p.h, you|
|000008e0| 20 63 61 6e 20 65 61 73 | 69 6c 79 20 6d 61 69 6e | can eas|ily main|
|000008f0| 74 61 69 6e 0a 58 61 20 | 63 6f 6d 6d 61 6e 64 20 |tain.Xa |command |
|00000900| 6c 6f 6f 6b 75 70 20 74 | 61 62 6c 65 2e 20 20 54 |lookup t|able. T|
|00000910| 68 65 20 74 61 62 6c 65 | 20 6d 75 73 74 20 62 65 |he table| must be|
|00000920| 20 6f 66 20 74 79 70 65 | 20 22 65 6e 74 72 79 20 | of type| "entry |
|00000930| 2a 22 2c 20 61 6e 64 20 | 79 6f 75 20 63 61 6e 20 |*", and |you can |
|00000940| 73 65 65 0a 58 69 6e 20 | 74 68 65 20 65 78 61 6d |see.Xin |the exam|
|00000950| 70 6c 65 20 63 6f 64 65 | 20 5b 74 65 73 74 2e 63 |ple code| [test.c|
|00000960| 2c 20 74 65 73 74 63 6d | 64 2e 63 2c 20 74 65 73 |, testcm|d.c, tes|
|00000970| 74 68 65 6c 70 2e 63 5d | 20 74 68 61 74 20 49 20 |thelp.c]| that I |
|00000980| 75 73 65 64 20 61 6e 20 | 61 67 67 72 65 61 67 61 |used an |aggreaga|
|00000990| 74 65 0a 58 61 72 72 61 | 79 20 6f 66 20 74 68 65 |te.Xarra|y of the|
|000009a0| 20 66 6f 72 6d 3a 0a 58 | 0a 58 65 6e 74 72 79 20 | form:.X|.Xentry |
|000009b0| 6c 69 73 74 5b 5d 20 3d | 20 7b 20 2e 2e 2e 20 7d |list[] =| { ... }|
|000009c0| 3b 0a 58 0a 58 54 68 65 | 20 66 69 72 73 74 20 22 |;.X.XThe| first "|
|000009d0| 65 6e 74 72 79 22 20 69 | 6e 20 74 68 65 20 6c 69 |entry" i|n the li|
|000009e0| 73 74 20 6d 75 73 74 20 | 68 61 76 65 20 61 20 63 |st must |have a c|
|000009f0| 6f 75 6e 74 20 61 6e 64 | 20 61 20 70 6f 69 6e 74 |ount and| a point|
|00000a00| 65 72 20 74 6f 20 61 6e | 20 65 72 72 6f 72 0a 58 |er to an| error.X|
|00000a10| 66 75 6e 63 74 69 6f 6e | 2e 20 20 49 66 20 79 6f |function|. If yo|
|00000a20| 75 20 68 61 76 65 20 6e | 6f 20 65 72 72 6f 72 20 |u have n|o error |
|00000a30| 66 75 6e 63 74 69 6f 6e | 2c 20 63 72 65 61 74 65 |function|, create|
|00000a40| 20 61 20 6e 75 6c 6c 20 | 66 75 6e 63 74 69 6f 6e | a null |function|
|00000a50| 2c 20 77 68 69 63 68 0a | 58 64 6f 65 73 20 6e 6f |, which.|Xdoes no|
|00000a60| 74 68 69 6e 67 2c 20 61 | 6e 64 20 75 73 65 20 61 |thing, a|nd use a|
|00000a70| 20 70 6f 69 6e 74 65 72 | 20 74 6f 20 69 74 2e 20 | pointer| to it. |
|00000a80| 20 53 69 6e 63 65 20 74 | 68 65 20 6e 75 6d 62 65 | Since t|he numbe|
|00000a90| 72 20 6f 63 63 75 70 69 | 65 73 20 74 68 65 0a 58 |r occupi|es the.X|
|00000aa0| 70 6f 73 69 74 69 6f 6e | 20 6f 66 20 61 20 63 68 |position| of a ch|
|00000ab0| 61 72 2a 2c 20 79 6f 75 | 20 68 61 76 65 20 74 6f |ar*, you| have to|
|00000ac0| 20 63 61 73 74 20 69 74 | 20 74 6f 20 73 75 63 68 | cast it| to such|
|00000ad0| 2e 20 20 69 2e 65 2e 2c | 20 69 66 20 79 6f 75 20 |. i.e.,| if you |
|00000ae0| 68 61 76 65 0a 58 23 64 | 65 66 69 6e 65 27 64 20 |have.X#d|efine'd |
|00000af0| 4e 55 4d 20 74 6f 20 74 | 68 65 20 6e 75 6d 62 65 |NUM to t|he numbe|
|00000b00| 72 20 6f 66 20 65 6c 65 | 6d 65 6e 74 73 2c 20 79 |r of ele|ments, y|
|00000b10| 6f 75 20 77 6f 75 6c 64 | 20 73 61 79 0a 58 0a 58 |ou would| say.X.X|
|00000b20| 65 6e 74 72 79 20 6c 69 | 73 74 5b 5d 20 3d 20 7b |entry li|st[] = {|
|00000b30| 0a 58 20 20 28 63 68 61 | 72 20 2a 29 4e 55 4d 2c |.X (cha|r *)NUM,|
|00000b40| 20 26 65 72 72 2c 0a 58 | 20 20 2e 2e 2e 0a 58 20 | &err,.X| ....X |
|00000b50| 20 7d 3b 0a 58 0a 58 77 | 68 65 72 65 20 65 72 72 | };.X.Xw|here err|
|00000b60| 20 69 73 20 74 68 65 20 | 65 72 72 6f 72 2d 68 61 | is the |error-ha|
|00000b70| 6e 64 6c 69 6e 67 20 66 | 75 6e 63 74 69 6f 6e 2e |ndling f|unction.|
|00000b80| 20 20 65 72 72 20 77 6f | 75 6c 64 20 62 65 20 63 | err wo|uld be c|
|00000b90| 61 6c 6c 65 64 20 77 68 | 65 6e 20 61 20 73 74 72 |alled wh|en a str|
|00000ba0| 69 6e 67 0a 58 6e 6f 74 | 20 69 6e 20 74 68 65 20 |ing.Xnot| in the |
|00000bb0| 6c 69 73 74 20 69 73 20 | 72 65 66 65 72 65 6e 63 |list is |referenc|
|00000bc0| 65 64 2e 0a 58 0a 58 4e | 6f 77 2c 20 74 68 65 20 |ed..X.XN|ow, the |
|00000bd0| 6c 69 73 74 20 69 73 20 | 6e 6f 74 20 74 68 65 20 |list is |not the |
|00000be0| 6f 62 6a 65 63 74 20 74 | 68 61 74 20 64 6f 65 73 |object t|hat does|
|00000bf0| 20 74 68 65 20 77 6f 72 | 6b 2e 20 20 41 6e 6f 74 | the wor|k. Anot|
|00000c00| 68 65 72 20 6f 62 6a 65 | 63 74 2c 20 6f 66 20 63 |her obje|ct, of c|
|00000c10| 6c 61 73 73 0a 58 22 6c | 6f 6f 6b 75 70 22 20 69 |lass.X"l|ookup" i|
|00000c20| 73 20 69 6e 69 74 69 61 | 6c 69 7a 65 64 20 77 69 |s initia|lized wi|
|00000c30| 74 68 20 61 20 70 6f 69 | 6e 74 65 72 20 74 6f 20 |th a poi|nter to |
|00000c40| 61 6e 20 22 65 6e 74 72 | 79 20 2a 22 2e 20 20 65 |an "entr|y *". e|
|00000c50| 2e 67 2e 2c 20 67 69 76 | 65 6e 20 74 68 65 0a 58 |.g., giv|en the.X|
|00000c60| 61 62 6f 76 65 20 65 78 | 61 6d 70 6c 65 2c 20 79 |above ex|ample, y|
|00000c70| 6f 75 20 63 6f 75 6c 64 | 20 73 61 79 3a 0a 58 0a |ou could| say:.X.|
|00000c80| 58 6c 6f 6f 6b 75 70 20 | 63 6d 64 28 6c 69 73 74 |Xlookup |cmd(list|
|00000c90| 29 3b 0a 58 0a 58 54 68 | 65 72 65 61 66 74 65 72 |);.X.XTh|ereafter|
|00000ca0| 2c 20 74 6f 20 72 65 74 | 72 69 65 76 65 20 74 68 |, to ret|rieve th|
|00000cb0| 65 20 66 75 6e 63 74 69 | 6f 6e 20 70 6f 69 6e 74 |e functi|on point|
|00000cc0| 65 72 20 64 65 73 69 72 | 65 64 2c 20 79 6f 75 20 |er desir|ed, you |
|00000cd0| 73 69 6d 70 6c 79 20 72 | 65 66 65 72 65 6e 63 65 |simply r|eference|
|00000ce0| 0a 58 22 63 6d 64 22 20 | 77 69 74 68 20 61 20 73 |.X"cmd" |with a s|
|00000cf0| 74 72 69 6e 67 3a 0a 58 | 0a 58 69 6e 74 20 28 2a |tring:.X|.Xint (*|
|00000d00| 70 72 6f 63 29 28 63 6f | 6e 73 74 20 63 68 61 72 |proc)(co|nst char|
|00000d10| 20 2a 29 3b 0a 58 70 72 | 6f 63 3d 63 6d 64 5b 22 | *);.Xpr|oc=cmd["|
|00000d20| 71 75 65 72 79 22 5d 3b | 0a 58 0a 58 54 68 69 73 |query"];|.X.XThis|
|00000d30| 20 77 6f 75 6c 64 20 63 | 61 75 73 65 20 22 70 72 | would c|ause "pr|
|00000d40| 6f 63 22 20 74 6f 20 70 | 6f 69 6e 74 20 74 6f 20 |oc" to p|oint to |
|00000d50| 74 68 65 20 66 75 6e 63 | 74 69 6f 6e 20 61 73 73 |the func|tion ass|
|00000d60| 6f 63 69 61 74 65 64 20 | 77 69 74 68 20 74 68 65 |ociated |with the|
|00000d70| 0a 58 77 6f 72 64 20 22 | 71 75 65 72 79 22 2c 20 |.Xword "|query", |
|00000d80| 69 66 20 61 6e 79 3b 20 | 6f 74 68 65 72 77 69 73 |if any; |otherwis|
|00000d90| 65 2c 20 69 74 20 77 6f | 75 6c 64 20 70 6f 69 6e |e, it wo|uld poin|
|00000da0| 74 20 74 6f 20 74 68 65 | 20 65 72 72 6f 72 20 66 |t to the| error f|
|00000db0| 75 6e 63 74 69 6f 6e 2c | 0a 58 77 68 69 63 68 20 |unction,|.Xwhich |
|00000dc0| 77 65 20 64 65 73 69 67 | 6e 61 74 65 64 20 61 62 |we desig|nated ab|
|00000dd0| 6f 76 65 20 74 6f 20 62 | 65 20 22 65 72 72 22 2e |ove to b|e "err".|
|00000de0| 20 20 4e 6f 77 20 79 6f | 75 20 63 61 6e 20 68 61 | Now yo|u can ha|
|00000df0| 70 70 69 6c 79 20 64 65 | 72 65 66 65 72 65 6e 63 |ppily de|referenc|
|00000e00| 65 20 74 68 65 0a 58 70 | 6f 69 6e 74 65 72 20 61 |e the.Xp|ointer a|
|00000e10| 6e 64 20 70 61 73 73 20 | 69 74 20 61 20 22 63 6f |nd pass |it a "co|
|00000e20| 6e 73 74 20 63 68 61 72 | 20 2a 22 3a 0a 58 0a 58 |nst char| *":.X.X|
|00000e30| 70 72 6f 63 28 22 74 65 | 73 74 69 6e 67 22 29 3b |proc("te|sting");|
|00000e40| 0a 58 0a 58 4e 6f 77 20 | 6e 6f 74 65 20 74 68 61 |.X.XNow |note tha|
|00000e50| 74 20 79 6f 75 20 63 61 | 6e 20 64 6f 20 62 6f 74 |t you ca|n do bot|
|00000e60| 68 20 6f 66 20 74 68 65 | 73 65 20 61 74 20 6f 6e |h of the|se at on|
|00000e70| 63 65 3a 0a 58 0a 58 63 | 6d 64 5b 22 71 75 65 72 |ce:.X.Xc|md["quer|
|00000e80| 79 22 5d 28 22 54 65 73 | 74 69 6e 67 22 29 3b 0a |y"]("Tes|ting");.|
|00000e90| 58 0a 58 49 73 6e 27 74 | 20 74 68 61 74 20 73 70 |X.XIsn't| that sp|
|00000ea0| 65 63 69 61 6c 3f 0a 58 | 0a 58 54 68 65 20 6f 6e |ecial?.X|.XThe on|
|00000eb0| 6c 79 20 64 69 66 66 65 | 72 65 6e 63 65 20 62 65 |ly diffe|rence be|
|00000ec0| 74 77 65 65 6e 20 6c 6f | 6f 6b 75 70 2e 63 20 61 |tween lo|okup.c a|
|00000ed0| 6e 64 20 6c 6f 6f 6b 75 | 70 32 2e 63 20 69 73 20 |nd looku|p2.c is |
|00000ee0| 74 68 65 20 69 6d 70 6c | 65 6d 65 6e 74 61 74 69 |the impl|ementati|
|00000ef0| 6f 6e 2e 0a 58 45 61 63 | 68 20 67 69 76 65 73 20 |on..XEac|h gives |
|00000f00| 79 6f 75 20 61 6e 20 61 | 64 76 61 6e 74 61 67 65 |you an a|dvantage|
|00000f10| 2e 20 20 49 66 20 79 6f | 75 72 20 6c 69 73 74 20 |. If yo|ur list |
|00000f20| 6f 66 20 6e 61 6d 65 73 | 20 69 73 20 73 6f 72 74 |of names| is sort|
|00000f30| 65 64 2c 20 75 73 65 0a | 58 6c 6f 6f 6b 75 70 2e |ed, use.|Xlookup.|
|00000f40| 63 20 73 69 6e 63 65 20 | 69 74 20 75 73 65 73 20 |c since |it uses |
|00000f50| 61 20 62 69 6e 61 72 79 | 20 73 65 61 72 63 68 2e |a binary| search.|
|00000f60| 20 20 4f 62 76 69 6f 75 | 73 6c 79 2c 20 69 66 20 | Obviou|sly, if |
|00000f70| 74 68 65 79 20 61 72 65 | 20 6e 6f 74 0a 58 69 6e |they are| not.Xin|
|00000f80| 20 61 6e 79 20 6f 72 64 | 65 72 2c 20 61 20 62 69 | any ord|er, a bi|
|00000f90| 6e 61 72 79 20 73 65 61 | 72 63 68 20 77 69 6c 6c |nary sea|rch will|
|00000fa0| 20 6e 6f 74 20 77 6f 72 | 6b 2c 20 73 6f 20 6c 6f | not wor|k, so lo|
|00000fb0| 6f 6b 75 70 32 2e 63 20 | 6a 75 73 74 20 64 6f 65 |okup2.c |just doe|
|00000fc0| 73 0a 58 61 20 6c 69 6e | 65 61 72 20 73 65 61 72 |s.Xa lin|ear sear|
|00000fd0| 63 68 2e 20 20 54 68 69 | 73 20 69 73 20 74 68 65 |ch. Thi|s is the|
|00000fe0| 20 6f 6e 6c 79 20 64 69 | 66 66 65 72 65 6e 63 65 | only di|fference|
|00000ff0| 20 62 65 74 77 65 65 6e | 20 74 68 65 20 74 77 6f | between| the two|
|00001000| 2e 0a 58 0a 58 0a 58 41 | 52 47 55 4d 45 4e 54 20 |..X.X.XA|RGUMENT |
|00001010| 54 59 50 45 0a 58 0a 58 | 41 6c 6c 20 6f 66 20 74 |TYPE.X.X|All of t|
|00001020| 68 65 20 66 75 6e 63 74 | 69 6f 6e 20 70 6f 69 6e |he funct|ion poin|
|00001030| 74 65 72 73 20 69 6e 20 | 74 68 65 20 22 65 6e 74 |ters in |the "ent|
|00001040| 72 79 22 20 6c 69 73 74 | 20 6d 75 73 74 20 74 61 |ry" list| must ta|
|00001050| 6b 65 20 74 68 65 20 73 | 61 6d 65 0a 58 61 72 67 |ke the s|ame.Xarg|
|00001060| 75 6d 65 6e 74 5b 73 5d | 2c 20 69 66 20 61 6e 79 |ument[s]|, if any|
|00001070| 2c 20 61 6e 64 20 72 65 | 74 75 72 6e 20 74 68 65 |, and re|turn the|
|00001080| 20 73 61 6d 65 20 76 61 | 6c 75 65 20 74 79 70 65 | same va|lue type|
|00001090| 2e 20 20 49 20 68 61 76 | 65 6e 27 74 20 62 75 69 |. I hav|en't bui|
|000010a0| 6c 74 0a 58 61 6e 79 20 | 65 6c 65 67 61 6e 74 20 |lt.Xany |elegant |
|000010b0| 6d 61 63 72 6f 73 2c 20 | 62 75 74 20 74 68 65 72 |macros, |but ther|
|000010c0| 65 20 61 72 65 20 23 64 | 65 66 69 6e 65 73 20 69 |e are #d|efines i|
|000010d0| 6e 20 22 6c 6f 6f 6b 75 | 70 2e 68 22 20 74 6f 20 |n "looku|p.h" to |
|000010e0| 68 61 6e 64 6c 65 20 62 | 6f 74 68 0a 58 6f 66 20 |handle b|oth.Xof |
|000010f0| 74 68 65 73 65 20 70 72 | 6f 62 6c 65 6d 73 20 69 |these pr|oblems i|
|00001100| 6e 20 61 20 6c 65 73 73 | 20 74 68 61 6e 20 65 6c |n a less| than el|
|00001110| 65 67 61 6e 74 20 6d 61 | 6e 6e 65 72 2e 0a 58 0a |egant ma|nner..X.|
|00001120| 58 54 68 65 20 74 77 6f | 20 6d 61 63 72 6f 73 20 |XThe two| macros |
|00001130| 41 52 47 5f 54 59 50 45 | 20 61 6e 64 20 52 45 54 |ARG_TYPE| and RET|
|00001140| 5f 54 59 50 45 20 64 65 | 66 69 6e 65 20 74 68 65 |_TYPE de|fine the|
|00001150| 20 61 72 67 75 6d 65 6e | 74 20 74 79 70 65 20 61 | argumen|t type a|
|00001160| 6e 64 20 76 61 6c 75 65 | 0a 58 76 61 6c 75 65 20 |nd value|.Xvalue |
|00001170| 72 65 74 75 72 6e 65 64 | 20 62 79 20 74 68 65 20 |returned| by the |
|00001180| 66 75 6e 63 74 69 6f 6e | 20 70 6f 69 6e 74 65 72 |function| pointer|
|00001190| 73 2e 20 20 4a 75 73 74 | 20 63 68 61 6e 67 65 20 |s. Just| change |
|000011a0| 74 68 65 73 65 20 74 6f | 20 68 61 6e 64 6c 65 20 |these to| handle |
|000011b0| 77 68 61 74 65 76 65 72 | 0a 58 74 79 70 65 73 20 |whatever|.Xtypes |
|000011c0| 79 6f 75 20 6c 69 6b 65 | 2e 0a 58 0a 58 0a 58 43 |you like|..X.X.XC|
|000011d0| 41 56 45 41 54 53 0a 58 | 0a 58 54 68 69 73 20 69 |AVEATS.X|.XThis i|
|000011e0| 73 20 6f 6e 65 20 6f 66 | 20 6d 79 20 66 69 72 73 |s one of| my firs|
|000011f0| 74 20 61 74 74 65 6d 70 | 74 73 20 61 74 20 43 2b |t attemp|ts at C+|
|00001200| 2b 3b 20 20 49 20 68 6f | 70 65 20 79 6f 75 20 66 |+; I ho|pe you f|
|00001210| 69 6e 64 20 69 74 20 75 | 73 65 66 75 6c 2e 20 20 |ind it u|seful. |
|00001220| 49 66 0a 58 79 6f 75 20 | 6d 61 6b 65 20 61 6e 79 |If.Xyou |make any|
|00001230| 20 6d 61 6a 6f 72 20 6d | 6f 64 69 66 69 63 61 74 | major m|odificat|
|00001240| 69 6f 6e 73 2c 20 6f 72 | 20 65 76 65 6e 20 6d 6f |ions, or| even mo|
|00001250| 72 65 20 69 6d 70 6f 72 | 74 61 6e 74 6c 79 2c 20 |re impor|tantly, |
|00001260| 69 66 20 79 6f 75 20 66 | 69 6e 64 20 61 6e 79 0a |if you f|ind any.|
|00001270| 58 62 75 67 73 2c 20 70 | 6c 65 61 73 65 20 6c 65 |Xbugs, p|lease le|
|00001280| 74 20 6d 65 20 6b 6e 6f | 77 20 73 6f 20 49 20 63 |t me kno|w so I c|
|00001290| 61 6e 20 66 69 78 20 6d | 79 20 73 6f 75 72 63 65 |an fix m|y source|
|000012a0| 20 61 6e 64 20 70 6f 73 | 74 20 74 68 65 20 70 61 | and pos|t the pa|
|000012b0| 74 63 68 65 73 20 66 6f | 72 0a 58 6f 6e 65 20 61 |tches fo|r.Xone a|
|000012c0| 6e 64 20 61 6c 6c 2e 0a | 58 0a 58 0a 58 43 4f 50 |nd all..|X.X.XCOP|
|000012d0| 59 52 49 47 48 54 0a 58 | 0a 58 49 20 74 68 65 20 |YRIGHT.X|.XI the |
|000012e0| 61 75 74 68 6f 72 20 68 | 65 72 65 62 79 20 70 6c |author h|ereby pl|
|000012f0| 61 63 65 20 74 68 69 73 | 20 63 6f 64 65 20 69 6e |ace this| code in|
|00001300| 20 74 68 65 20 70 75 62 | 6c 69 63 20 64 6f 6d 61 | the pub|lic doma|
|00001310| 69 6e 2e 20 20 4d 61 6b | 65 20 65 6e 6f 75 67 68 |in. Mak|e enough|
|00001320| 0a 58 6d 6f 6e 65 79 20 | 74 6f 20 62 75 79 20 43 |.Xmoney |to buy C|
|00001330| 61 6e 61 64 61 20 61 6e | 64 20 68 69 72 65 20 6d |anada an|d hire m|
|00001340| 65 20 61 73 20 50 72 69 | 6d 65 20 4d 69 6e 69 73 |e as Pri|me Minis|
|00001350| 74 65 72 21 0a 58 0a 58 | 0a 58 41 55 54 48 4f 52 |ter!.X.X|.XAUTHOR|
|00001360| 0a 58 0a 58 52 65 69 64 | 20 45 6c 6c 69 73 0a 58 |.X.XReid| Ellis.X|
|00001370| 31 37 36 20 42 72 6f 6f | 6b 62 61 6e 6b 73 20 44 |176 Broo|kbanks D|
|00001380| 72 69 76 65 0a 58 44 6f | 6e 20 4d 69 6c 6c 73 2c |rive.XDo|n Mills,|
|00001390| 20 4f 6e 74 61 72 69 6f | 0a 58 4d 33 41 20 32 54 | Ontario|.XM3A 2T|
|000013a0| 35 0a 58 43 41 4e 41 44 | 41 0a 58 2b 31 20 34 31 |5.XCANAD|A.X+1 41|
|000013b0| 36 20 34 34 36 20 31 36 | 34 34 0a 58 72 61 65 40 |6 446 16|44.Xrae@|
|000013c0| 67 65 61 63 6c 69 62 2e | 75 75 63 70 20 69 66 20 |geaclib.|uucp if |
|000013d0| 79 6f 75 27 72 65 20 6c | 75 63 6b 79 2c 20 6f 72 |you're l|ucky, or|
|000013e0| 20 65 6c 73 65 20 67 65 | 61 63 6c 69 62 21 72 61 | else ge|aclib!ra|
|000013f0| 65 40 67 65 61 63 2e 75 | 75 63 70 0a 45 4e 44 5f |e@geac.u|ucp.END_|
|00001400| 4f 46 5f 52 45 41 44 4d | 45 0a 69 66 20 74 65 73 |OF_READM|E.if tes|
|00001410| 74 20 32 38 32 37 20 2d | 6e 65 20 60 77 63 20 2d |t 2827 -|ne `wc -|
|00001420| 63 20 3c 52 45 41 44 4d | 45 60 3b 20 74 68 65 6e |c <READM|E`; then|
|00001430| 0a 20 20 20 20 65 63 68 | 6f 20 73 68 61 72 3a 20 |. ech|o shar: |
|00001440| 5c 22 52 45 41 44 4d 45 | 5c 22 20 75 6e 70 61 63 |\"README|\" unpac|
|00001450| 6b 65 64 20 77 69 74 68 | 20 77 72 6f 6e 67 20 73 |ked with| wrong s|
|00001460| 69 7a 65 21 0a 66 69 0a | 23 20 65 6e 64 20 6f 66 |ize!.fi.|# end of|
|00001470| 20 6f 76 65 72 77 72 69 | 74 69 6e 67 20 63 68 65 | overwri|ting che|
|00001480| 63 6b 0a 66 69 0a 69 66 | 20 74 65 73 74 20 2d 66 |ck.fi.if| test -f|
|00001490| 20 6c 6f 6f 6b 75 70 2e | 63 20 2d 61 20 22 24 7b | lookup.|c -a "${|
|000014a0| 31 7d 22 20 21 3d 20 22 | 2d 63 22 20 3b 20 74 68 |1}" != "|-c" ; th|
|000014b0| 65 6e 20 0a 20 20 65 63 | 68 6f 20 73 68 61 72 3a |en . ec|ho shar:|
|000014c0| 20 57 69 6c 6c 20 6e 6f | 74 20 6f 76 65 72 2d 77 | Will no|t over-w|
|000014d0| 72 69 74 65 20 65 78 69 | 73 74 69 6e 67 20 66 69 |rite exi|sting fi|
|000014e0| 6c 65 20 5c 22 6c 6f 6f | 6b 75 70 2e 63 5c 22 0a |le \"loo|kup.c\".|
|000014f0| 65 6c 73 65 0a 65 63 68 | 6f 20 73 68 61 72 3a 20 |else.ech|o shar: |
|00001500| 45 78 74 72 61 63 74 69 | 6e 67 20 5c 22 6c 6f 6f |Extracti|ng \"loo|
|00001510| 6b 75 70 2e 63 5c 22 20 | 5c 28 36 35 32 20 63 68 |kup.c\" |\(652 ch|
|00001520| 61 72 61 63 74 65 72 73 | 5c 29 0a 73 65 64 20 22 |aracters|\).sed "|
|00001530| 73 2f 5e 58 2f 2f 22 20 | 3e 6c 6f 6f 6b 75 70 2e |s/^X//" |>lookup.|
|00001540| 63 20 3c 3c 27 45 4e 44 | 5f 4f 46 5f 6c 6f 6f 6b |c <<'END|_OF_look|
|00001550| 75 70 2e 63 27 0a 58 23 | 69 6e 63 6c 75 64 65 20 |up.c'.X#|include |
|00001560| 3c 73 74 72 65 61 6d 2e | 68 3e 0a 58 23 69 6e 63 |<stream.|h>.X#inc|
|00001570| 6c 75 64 65 20 3c 73 74 | 72 69 6e 67 2e 68 3e 0a |lude <st|ring.h>.|
|00001580| 58 23 69 6e 63 6c 75 64 | 65 20 22 6c 6f 6f 6b 75 |X#includ|e "looku|
|00001590| 70 2e 68 22 0a 58 0a 58 | 70 72 6f 63 20 6c 6f 6f |p.h".X.X|proc loo|
|000015a0| 6b 75 70 3a 3a 6f 70 65 | 72 61 74 6f 72 5b 5d 28 |kup::ope|rator[](|
|000015b0| 63 6f 6e 73 74 20 63 68 | 61 72 20 2a 73 74 72 29 |const ch|ar *str)|
|000015c0| 0a 58 20 20 7b 0a 58 20 | 20 69 6e 74 20 6e 3b 0a |.X {.X | int n;.|
|000015d0| 58 20 20 65 6e 74 72 79 | 0a 58 20 20 20 20 2a 75 |X entry|.X *u|
|000015e0| 70 70 65 72 20 3d 20 74 | 61 62 6c 65 20 2b 20 6d |pper = t|able + m|
|000015f0| 61 78 20 2d 20 31 2c 0a | 58 20 20 20 20 2a 6c 6f |ax - 1,.|X *lo|
|00001600| 77 65 72 20 3d 20 74 61 | 62 6c 65 2c 0a 58 20 20 |wer = ta|ble,.X |
|00001610| 20 20 2a 6d 69 64 20 3d | 20 6c 6f 77 65 72 20 2b | *mid =| lower +|
|00001620| 20 28 75 70 70 65 72 2d | 6c 6f 77 65 72 29 2f 32 | (upper-|lower)/2|
|00001630| 3b 0a 58 0a 58 20 66 6f | 72 28 6e 3d 31 3b 20 6e |;.X.X fo|r(n=1; n|
|00001640| 20 26 26 20 75 70 70 65 | 72 20 2d 20 6c 6f 77 65 | && uppe|r - lowe|
|00001650| 72 20 3e 20 31 3b 20 29 | 0a 58 20 20 20 20 7b 0a |r > 1; )|.X {.|
|00001660| 58 20 20 20 20 6e 20 3d | 20 73 74 72 63 6d 70 28 |X n =| strcmp(|
|00001670| 73 74 72 2c 20 6d 69 64 | 2d 3e 6e 61 6d 65 29 3b |str, mid|->name);|
|00001680| 0a 58 20 20 20 20 69 66 | 28 6e 20 3d 3d 20 30 29 |.X if|(n == 0)|
|00001690| 0a 58 20 20 20 20 20 20 | 75 70 70 65 72 20 3d 20 |.X |upper = |
|000016a0| 6c 6f 77 65 72 20 3d 20 | 6d 69 64 3b 0a 58 20 20 |lower = |mid;.X |
|000016b0| 20 20 65 6c 73 65 0a 58 | 20 20 20 20 20 20 7b 0a | else.X| {.|
|000016c0| 58 20 20 20 20 20 20 69 | 66 28 6e 20 3c 20 30 29 |X i|f(n < 0)|
|000016d0| 20 75 70 70 65 72 20 3d | 20 6d 69 64 3b 0a 58 20 | upper =| mid;.X |
|000016e0| 20 20 20 20 20 65 6c 73 | 65 20 20 20 20 20 20 6c | els|e l|
|000016f0| 6f 77 65 72 20 3d 20 6d | 69 64 3b 0a 58 20 20 20 |ower = m|id;.X |
|00001700| 20 20 20 6d 69 64 20 3d | 20 6c 6f 77 65 72 20 2b | mid =| lower +|
|00001710| 20 28 75 70 70 65 72 20 | 2d 20 6c 6f 77 65 72 29 | (upper |- lower)|
|00001720| 2f 32 3b 0a 58 20 20 20 | 20 20 20 7d 0a 58 20 20 |/2;.X | }.X |
|00001730| 20 20 7d 0a 58 0a 58 20 | 20 69 66 28 6e 20 3c 20 | }.X.X | if(n < |
|00001740| 30 29 20 6e 20 3d 20 73 | 74 72 63 6d 70 28 73 74 |0) n = s|trcmp(st|
|00001750| 72 2c 20 6d 69 64 2d 3e | 6e 61 6d 65 29 3b 0a 58 |r, mid->|name);.X|
|00001760| 20 20 65 6c 73 65 20 69 | 66 28 6e 20 3e 20 30 29 | else i|f(n > 0)|
|00001770| 0a 58 20 20 20 20 7b 0a | 58 20 20 20 20 6d 69 64 |.X {.|X mid|
|00001780| 20 3d 20 75 70 70 65 72 | 3b 0a 58 20 20 20 20 6e | = upper|;.X n|
|00001790| 20 3d 20 73 74 72 63 6d | 70 28 73 74 72 2c 20 6d | = strcm|p(str, m|
|000017a0| 69 64 2d 3e 6e 61 6d 65 | 29 3b 0a 58 20 20 20 20 |id->name|);.X |
|000017b0| 7d 0a 58 0a 58 20 20 69 | 66 28 6e 29 20 72 65 74 |}.X.X i|f(n) ret|
|000017c0| 75 72 6e 20 64 66 6c 74 | 3b 20 20 20 2f 2f 20 6e |urn dflt|; // n|
|000017d0| 6f 74 20 69 6e 20 74 61 | 62 6c 65 0a 58 20 20 65 |ot in ta|ble.X e|
|000017e0| 6c 73 65 20 20 72 65 74 | 75 72 6e 20 6d 69 64 2d |lse ret|urn mid-|
|000017f0| 3e 66 3b 20 2f 2f 20 66 | 6f 75 6e 64 20 69 74 0a |>f; // f|ound it.|
|00001800| 58 20 20 7d 0a 45 4e 44 | 5f 4f 46 5f 6c 6f 6f 6b |X }.END|_OF_look|
|00001810| 75 70 2e 63 0a 69 66 20 | 74 65 73 74 20 36 35 32 |up.c.if |test 652|
|00001820| 20 2d 6e 65 20 60 77 63 | 20 2d 63 20 3c 6c 6f 6f | -ne `wc| -c <loo|
|00001830| 6b 75 70 2e 63 60 3b 20 | 74 68 65 6e 0a 20 20 20 |kup.c`; |then. |
|00001840| 20 65 63 68 6f 20 73 68 | 61 72 3a 20 5c 22 6c 6f | echo sh|ar: \"lo|
|00001850| 6f 6b 75 70 2e 63 5c 22 | 20 75 6e 70 61 63 6b 65 |okup.c\"| unpacke|
|00001860| 64 20 77 69 74 68 20 77 | 72 6f 6e 67 20 73 69 7a |d with w|rong siz|
|00001870| 65 21 0a 66 69 0a 23 20 | 65 6e 64 20 6f 66 20 6f |e!.fi.# |end of o|
|00001880| 76 65 72 77 72 69 74 69 | 6e 67 20 63 68 65 63 6b |verwriti|ng check|
|00001890| 0a 66 69 0a 69 66 20 74 | 65 73 74 20 2d 66 20 6c |.fi.if t|est -f l|
|000018a0| 6f 6f 6b 75 70 2e 68 20 | 2d 61 20 22 24 7b 31 7d |ookup.h |-a "${1}|
|000018b0| 22 20 21 3d 20 22 2d 63 | 22 20 3b 20 74 68 65 6e |" != "-c|" ; then|
|000018c0| 20 0a 20 20 65 63 68 6f | 20 73 68 61 72 3a 20 57 | . echo| shar: W|
|000018d0| 69 6c 6c 20 6e 6f 74 20 | 6f 76 65 72 2d 77 72 69 |ill not |over-wri|
|000018e0| 74 65 20 65 78 69 73 74 | 69 6e 67 20 66 69 6c 65 |te exist|ing file|
|000018f0| 20 5c 22 6c 6f 6f 6b 75 | 70 2e 68 5c 22 0a 65 6c | \"looku|p.h\".el|
|00001900| 73 65 0a 65 63 68 6f 20 | 73 68 61 72 3a 20 45 78 |se.echo |shar: Ex|
|00001910| 74 72 61 63 74 69 6e 67 | 20 5c 22 6c 6f 6f 6b 75 |tracting| \"looku|
|00001920| 70 2e 68 5c 22 20 5c 28 | 33 39 32 20 63 68 61 72 |p.h\" \(|392 char|
|00001930| 61 63 74 65 72 73 5c 29 | 0a 73 65 64 20 22 73 2f |acters\)|.sed "s/|
|00001940| 5e 58 2f 2f 22 20 3e 6c | 6f 6f 6b 75 70 2e 68 20 |^X//" >l|ookup.h |
|00001950| 3c 3c 27 45 4e 44 5f 4f | 46 5f 6c 6f 6f 6b 75 70 |<<'END_O|F_lookup|
|00001960| 2e 68 27 0a 58 23 69 66 | 6e 64 65 66 20 4c 4f 4f |.h'.X#if|ndef LOO|
|00001970| 4b 55 50 48 0a 58 23 64 | 65 66 69 6e 65 20 4c 4f |KUPH.X#d|efine LO|
|00001980| 4f 4b 55 50 48 0a 58 0a | 58 23 64 65 66 69 6e 65 |OKUPH.X.|X#define|
|00001990| 20 41 52 47 5f 54 59 50 | 45 20 63 6f 6e 73 74 20 | ARG_TYP|E const |
|000019a0| 63 68 61 72 20 2a 0a 58 | 23 64 65 66 69 6e 65 20 |char *.X|#define |
|000019b0| 52 45 54 5f 54 59 50 45 | 20 69 6e 74 0a 58 0a 58 |RET_TYPE| int.X.X|
|000019c0| 74 79 70 65 64 65 66 20 | 52 45 54 5f 54 59 50 45 |typedef |RET_TYPE|
|000019d0| 20 28 2a 70 72 6f 63 29 | 28 41 52 47 5f 54 59 50 | (*proc)|(ARG_TYP|
|000019e0| 45 29 3b 0a 58 0a 58 73 | 74 72 75 63 74 20 65 6e |E);.X.Xs|truct en|
|000019f0| 74 72 79 20 7b 0a 58 09 | 63 6f 6e 73 74 20 63 68 |try {.X.|const ch|
|00001a00| 61 72 20 2a 6e 61 6d 65 | 3b 0a 58 09 70 72 6f 63 |ar *name|;.X.proc|
|00001a10| 20 66 3b 0a 58 09 7d 3b | 0a 58 0a 58 63 6c 61 73 | f;.X.};|.X.Xclas|
|00001a20| 73 20 6c 6f 6f 6b 75 70 | 20 7b 0a 58 09 65 6e 74 |s lookup| {.X.ent|
|00001a30| 72 79 20 2a 74 61 62 6c | 65 3b 0a 58 09 70 72 6f |ry *tabl|e;.X.pro|
|00001a40| 63 20 64 66 6c 74 3b 0a | 58 09 69 6e 74 20 6d 61 |c dflt;.|X.int ma|
|00001a50| 78 3b 0a 58 70 75 62 6c | 69 63 3a 0a 58 09 6c 6f |x;.Xpubl|ic:.X.lo|
|00001a60| 6f 6b 75 70 28 65 6e 74 | 72 79 20 2a 74 29 20 7b |okup(ent|ry *t) {|
|00001a70| 0a 58 09 09 64 66 6c 74 | 20 3d 20 74 2d 3e 66 3b |.X..dflt| = t->f;|
|00001a80| 0a 58 09 09 6d 61 78 20 | 3d 20 69 6e 74 28 74 2d |.X..max |= int(t-|
|00001a90| 3e 6e 61 6d 65 29 3b 0a | 58 09 09 74 61 62 6c 65 |>name);.|X..table|
|00001aa0| 20 3d 20 74 20 2b 20 31 | 3b 0a 58 09 09 7d 0a 58 | = t + 1|;.X..}.X|
|00001ab0| 09 2f 2f 20 54 68 69 73 | 20 72 65 61 6c 6c 79 20 |.// This| really |
|00001ac0| 64 6f 65 73 20 74 61 6b | 65 20 61 20 63 6f 6e 73 |does tak|e a cons|
|00001ad0| 74 20 63 68 61 72 20 2a | 0a 58 09 70 72 6f 63 20 |t char *|.X.proc |
|00001ae0| 6f 70 65 72 61 74 6f 72 | 5b 5d 28 63 6f 6e 73 74 |operator|[](const|
|00001af0| 20 63 68 61 72 20 2a 29 | 3b 0a 58 09 7d 3b 0a 58 | char *)|;.X.};.X|
|00001b00| 23 65 6e 64 69 66 0a 45 | 4e 44 5f 4f 46 5f 6c 6f |#endif.E|ND_OF_lo|
|00001b10| 6f 6b 75 70 2e 68 0a 69 | 66 20 74 65 73 74 20 33 |okup.h.i|f test 3|
|00001b20| 39 32 20 2d 6e 65 20 60 | 77 63 20 2d 63 20 3c 6c |92 -ne `|wc -c <l|
|00001b30| 6f 6f 6b 75 70 2e 68 60 | 3b 20 74 68 65 6e 0a 20 |ookup.h`|; then. |
|00001b40| 20 20 20 65 63 68 6f 20 | 73 68 61 72 3a 20 5c 22 | echo |shar: \"|
|00001b50| 6c 6f 6f 6b 75 70 2e 68 | 5c 22 20 75 6e 70 61 63 |lookup.h|\" unpac|
|00001b60| 6b 65 64 20 77 69 74 68 | 20 77 72 6f 6e 67 20 73 |ked with| wrong s|
|00001b70| 69 7a 65 21 0a 66 69 0a | 23 20 65 6e 64 20 6f 66 |ize!.fi.|# end of|
|00001b80| 20 6f 76 65 72 77 72 69 | 74 69 6e 67 20 63 68 65 | overwri|ting che|
|00001b90| 63 6b 0a 66 69 0a 69 66 | 20 74 65 73 74 20 2d 66 |ck.fi.if| test -f|
|00001ba0| 20 6c 6f 6f 6b 75 70 32 | 2e 63 20 2d 61 20 22 24 | lookup2|.c -a "$|
|00001bb0| 7b 31 7d 22 20 21 3d 20 | 22 2d 63 22 20 3b 20 74 |{1}" != |"-c" ; t|
|00001bc0| 68 65 6e 20 0a 20 20 65 | 63 68 6f 20 73 68 61 72 |hen . e|cho shar|
|00001bd0| 3a 20 57 69 6c 6c 20 6e | 6f 74 20 6f 76 65 72 2d |: Will n|ot over-|
|00001be0| 77 72 69 74 65 20 65 78 | 69 73 74 69 6e 67 20 66 |write ex|isting f|
|00001bf0| 69 6c 65 20 5c 22 6c 6f | 6f 6b 75 70 32 2e 63 5c |ile \"lo|okup2.c\|
|00001c00| 22 0a 65 6c 73 65 0a 65 | 63 68 6f 20 73 68 61 72 |".else.e|cho shar|
|00001c10| 3a 20 45 78 74 72 61 63 | 74 69 6e 67 20 5c 22 6c |: Extrac|ting \"l|
|00001c20| 6f 6f 6b 75 70 32 2e 63 | 5c 22 20 5c 28 32 36 33 |ookup2.c|\" \(263|
|00001c30| 20 63 68 61 72 61 63 74 | 65 72 73 5c 29 0a 73 65 | charact|ers\).se|
|00001c40| 64 20 22 73 2f 5e 58 2f | 2f 22 20 3e 6c 6f 6f 6b |d "s/^X/|/" >look|
|00001c50| 75 70 32 2e 63 20 3c 3c | 27 45 4e 44 5f 4f 46 5f |up2.c <<|'END_OF_|
|00001c60| 6c 6f 6f 6b 75 70 32 2e | 63 27 0a 58 23 69 6e 63 |lookup2.|c'.X#inc|
|00001c70| 6c 75 64 65 20 3c 73 74 | 72 65 61 6d 2e 68 3e 0a |lude <st|ream.h>.|
|00001c80| 58 23 69 6e 63 6c 75 64 | 65 20 3c 73 74 72 69 6e |X#includ|e <strin|
|00001c90| 67 2e 68 3e 0a 58 23 69 | 6e 63 6c 75 64 65 20 22 |g.h>.X#i|nclude "|
|00001ca0| 6c 6f 6f 6b 75 70 2e 68 | 22 0a 58 0a 58 70 72 6f |lookup.h|".X.Xpro|
|00001cb0| 63 20 6c 6f 6f 6b 75 70 | 3a 3a 6f 70 65 72 61 74 |c lookup|::operat|
|00001cc0| 6f 72 5b 5d 28 63 6f 6e | 73 74 20 63 68 61 72 20 |or[](con|st char |
|00001cd0| 2a 73 74 72 29 0a 58 20 | 20 7b 0a 58 20 20 65 6e |*str).X | {.X en|
|00001ce0| 74 72 79 20 2a 74 3d 74 | 61 62 6c 65 3b 0a 58 0a |try *t=t|able;.X.|
|00001cf0| 58 20 20 66 6f 72 28 3b | 20 74 2d 74 61 62 6c 65 |X for(;| t-table|
|00001d00| 20 3c 20 6d 61 78 3b 20 | 74 2b 2b 29 0a 58 20 20 | < max; |t++).X |
|00001d10| 20 20 69 66 28 21 73 74 | 72 63 6d 70 28 74 2d 3e | if(!st|rcmp(t->|
|00001d20| 6e 61 6d 65 2c 20 73 74 | 72 29 29 0a 58 20 20 20 |name, st|r)).X |
|00001d30| 20 20 20 62 72 65 61 6b | 3b 0a 58 0a 58 20 20 69 | break|;.X.X i|
|00001d40| 66 28 74 2d 74 61 62 6c | 65 3c 6d 61 78 29 20 72 |f(t-tabl|e<max) r|
|00001d50| 65 74 75 72 6e 20 74 2d | 3e 66 3b 0a 58 20 20 65 |eturn t-|>f;.X e|
|00001d60| 6c 73 65 20 20 20 20 20 | 20 20 20 20 20 20 20 72 |lse | r|
|00001d70| 65 74 75 72 6e 20 64 66 | 6c 74 3b 0a 58 20 20 7d |eturn df|lt;.X }|
|00001d80| 0a 45 4e 44 5f 4f 46 5f | 6c 6f 6f 6b 75 70 32 2e |.END_OF_|lookup2.|
|00001d90| 63 0a 69 66 20 74 65 73 | 74 20 32 36 33 20 2d 6e |c.if tes|t 263 -n|
|00001da0| 65 20 60 77 63 20 2d 63 | 20 3c 6c 6f 6f 6b 75 70 |e `wc -c| <lookup|
|00001db0| 32 2e 63 60 3b 20 74 68 | 65 6e 0a 20 20 20 20 65 |2.c`; th|en. e|
|00001dc0| 63 68 6f 20 73 68 61 72 | 3a 20 5c 22 6c 6f 6f 6b |cho shar|: \"look|
|00001dd0| 75 70 32 2e 63 5c 22 20 | 75 6e 70 61 63 6b 65 64 |up2.c\" |unpacked|
|00001de0| 20 77 69 74 68 20 77 72 | 6f 6e 67 20 73 69 7a 65 | with wr|ong size|
|00001df0| 21 0a 66 69 0a 23 20 65 | 6e 64 20 6f 66 20 6f 76 |!.fi.# e|nd of ov|
|00001e00| 65 72 77 72 69 74 69 6e | 67 20 63 68 65 63 6b 0a |erwritin|g check.|
|00001e10| 66 69 0a 69 66 20 74 65 | 73 74 20 2d 66 20 74 65 |fi.if te|st -f te|
|00001e20| 73 74 2e 63 20 2d 61 20 | 22 24 7b 31 7d 22 20 21 |st.c -a |"${1}" !|
|00001e30| 3d 20 22 2d 63 22 20 3b | 20 74 68 65 6e 20 0a 20 |= "-c" ;| then . |
|00001e40| 20 65 63 68 6f 20 73 68 | 61 72 3a 20 57 69 6c 6c | echo sh|ar: Will|
|00001e50| 20 6e 6f 74 20 6f 76 65 | 72 2d 77 72 69 74 65 20 | not ove|r-write |
|00001e60| 65 78 69 73 74 69 6e 67 | 20 66 69 6c 65 20 5c 22 |existing| file \"|
|00001e70| 74 65 73 74 2e 63 5c 22 | 0a 65 6c 73 65 0a 65 63 |test.c\"|.else.ec|
|00001e80| 68 6f 20 73 68 61 72 3a | 20 45 78 74 72 61 63 74 |ho shar:| Extract|
|00001e90| 69 6e 67 20 5c 22 74 65 | 73 74 2e 63 5c 22 20 5c |ing \"te|st.c\" \|
|00001ea0| 28 38 38 32 20 63 68 61 | 72 61 63 74 65 72 73 5c |(882 cha|racters\|
|00001eb0| 29 0a 73 65 64 20 22 73 | 2f 5e 58 2f 2f 22 20 3e |).sed "s|/^X//" >|
|00001ec0| 74 65 73 74 2e 63 20 3c | 3c 27 45 4e 44 5f 4f 46 |test.c <|<'END_OF|
|00001ed0| 5f 74 65 73 74 2e 63 27 | 0a 58 23 69 6e 63 6c 75 |_test.c'|.X#inclu|
|00001ee0| 64 65 20 3c 73 74 72 65 | 61 6d 2e 68 3e 0a 58 23 |de <stre|am.h>.X#|
|00001ef0| 69 6e 63 6c 75 64 65 20 | 3c 73 74 72 69 6e 67 2e |include |<string.|
|00001f00| 68 3e 0a 58 23 69 6e 63 | 6c 75 64 65 20 22 6c 6f |h>.X#inc|lude "lo|
|00001f10| 6f 6b 75 70 2e 68 22 0a | 58 0a 58 65 78 74 65 72 |okup.h".|X.Xexter|
|00001f20| 6e 20 52 45 54 5f 54 59 | 50 45 0a 58 09 61 28 41 |n RET_TY|PE.X.a(A|
|00001f30| 52 47 5f 54 59 50 45 29 | 2c 0a 58 09 62 28 41 52 |RG_TYPE)|,.X.b(AR|
|00001f40| 47 5f 54 59 50 45 29 2c | 0a 58 09 63 28 41 52 47 |G_TYPE),|.X.c(ARG|
|00001f50| 5f 54 59 50 45 29 2c 0a | 58 09 68 65 6c 70 28 41 |_TYPE),.|X.help(A|
|00001f60| 52 47 5f 54 59 50 45 29 | 2c 0a 58 09 6f 6f 70 73 |RG_TYPE)|,.X.oops|
|00001f70| 28 41 52 47 5f 54 59 50 | 45 29 3b 0a 58 0a 58 65 |(ARG_TYP|E);.X.Xe|
|00001f80| 6e 74 72 79 20 6c 69 73 | 74 5b 5d 20 3d 20 7b 0a |ntry lis|t[] = {.|
|00001f90| 58 20 20 28 63 68 61 72 | 20 2a 29 34 2c 20 26 6f |X (char| *)4, &o|
|00001fa0| 6f 70 73 2c 0a 58 20 20 | 22 61 63 6d 64 22 2c 20 |ops,.X |"acmd", |
|00001fb0| 26 61 2c 0a 58 20 20 22 | 62 63 6d 64 22 2c 20 26 |&a,.X "|bcmd", &|
|00001fc0| 62 2c 0a 58 20 20 22 63 | 22 2c 20 26 63 2c 0a 58 |b,.X "c|", &c,.X|
|00001fd0| 20 20 22 68 65 6c 70 22 | 2c 20 26 68 65 6c 70 2c | "help"|, &help,|
|00001fe0| 0a 58 20 20 7d 3b 0a 58 | 0a 58 69 6e 74 20 6d 61 |.X };.X|.Xint ma|
|00001ff0| 69 6e 28 69 6e 74 20 61 | 72 67 63 2c 20 63 68 61 |in(int a|rgc, cha|
|00002000| 72 20 2a 61 72 67 76 5b | 5d 29 0a 58 20 20 7b 0a |r *argv[|]).X {.|
|00002010| 58 20 20 63 68 61 72 20 | 2a 70 72 6f 67 6e 61 6d |X char |*prognam|
|00002020| 65 20 3d 20 61 72 67 76 | 5b 30 5d 3b 0a 58 20 20 |e = argv|[0];.X |
|00002030| 6c 6f 6f 6b 75 70 20 63 | 6f 6d 6d 61 6e 64 28 6c |lookup c|ommand(l|
|00002040| 69 73 74 29 3b 0a 58 20 | 20 63 68 61 72 20 77 6f |ist);.X | char wo|
|00002050| 72 64 5b 32 30 30 5d 3b | 20 2f 2f 20 6f 66 20 74 |rd[200];| // of t|
|00002060| 79 70 65 20 41 52 47 5f | 54 59 50 45 0a 58 20 20 |ype ARG_|TYPE.X |
|00002070| 69 6e 74 20 69 3b 0a 58 | 0a 58 20 20 61 72 67 63 |int i;.X|.X argc|
|00002080| 2d 2d 3b 20 2f 2f 20 74 | 6f 20 73 68 75 74 20 75 |--; // t|o shut u|
|00002090| 70 20 43 43 0a 58 0a 58 | 20 20 77 68 69 6c 65 28 |p CC.X.X| while(|
|000020a0| 63 6f 75 74 20 3c 3c 20 | 22 25 20 22 2c 20 63 69 |cout << |"% ", ci|
|000020b0| 6e 20 3e 3e 20 77 6f 72 | 64 20 26 26 20 73 74 72 |n >> wor|d && str|
|000020c0| 63 6d 70 28 77 6f 72 64 | 2c 20 22 71 75 69 74 22 |cmp(word|, "quit"|
|000020d0| 29 29 0a 58 20 20 20 20 | 7b 0a 58 0a 58 20 20 20 |)).X |{.X.X |
|000020e0| 20 2f 2f 20 4e 6f 74 65 | 20 74 68 61 74 20 69 6e | // Note| that in|
|000020f0| 20 74 68 65 20 6e 65 78 | 74 20 73 74 61 74 65 6d | the nex|t statem|
|00002100| 65 6e 74 2c 20 77 65 20 | 61 72 65 20 69 6e 0a 58 |ent, we |are in.X|
|00002110| 20 20 20 20 2f 2f 20 66 | 61 63 74 20 73 61 79 69 | // f|act sayi|
|00002120| 6e 67 20 63 6f 6d 6d 61 | 6e 64 5b 63 6f 6e 73 74 |ng comma|nd[const|
|00002130| 20 63 68 61 72 20 2a 5d | 28 41 52 47 5f 54 59 50 | char *]|(ARG_TYP|
|00002140| 45 29 0a 58 20 20 20 20 | 2f 2f 20 49 6e 20 74 68 |E).X |// In th|
|00002150| 69 73 20 63 61 73 65 2c | 20 41 52 47 5f 54 59 50 |is case,| ARG_TYP|
|00002160| 45 20 2a 69 73 2a 20 63 | 6f 6e 73 74 20 63 68 61 |E *is* c|onst cha|
|00002170| 72 20 2a 2c 20 73 6f 20 | 77 65 20 0a 58 20 20 20 |r *, so |we .X |
|00002180| 20 2f 2f 20 61 72 65 20 | 6a 75 73 74 20 70 61 73 | // are |just pas|
|00002190| 73 69 6e 67 20 74 68 65 | 20 73 61 6d 65 20 74 68 |sing the| same th|
|000021a0| 69 6e 67 20 74 6f 20 62 | 6f 74 68 20 5b 5d 20 61 |ing to b|oth [] a|
|000021b0| 6e 64 20 28 29 2e 0a 58 | 0a 58 20 20 20 20 69 66 |nd ()..X|.X if|
|000021c0| 28 69 20 3d 20 63 6f 6d | 6d 61 6e 64 5b 77 6f 72 |(i = com|mand[wor|
|000021d0| 64 5d 28 77 6f 72 64 29 | 29 0a 58 20 20 20 20 20 |d](word)|).X |
|000021e0| 20 7b 0a 58 20 20 20 20 | 20 20 2f 2f 20 74 68 65 | {.X | // the|
|000021f0| 20 66 75 6e 63 74 69 6f | 6e 20 72 65 74 75 72 6e | functio|n return|
|00002200| 65 64 20 61 20 6e 6f 6e | 2d 7a 65 72 6f 20 72 65 |ed a non|-zero re|
|00002210| 73 75 6c 74 0a 58 20 20 | 20 20 20 20 63 65 72 72 |sult.X | cerr|
|00002220| 20 3c 3c 20 66 6f 72 6d | 28 22 25 73 3a 20 25 73 | << form|("%s: %s|
|00002230| 20 72 65 74 75 72 6e 65 | 64 20 25 64 5c 6e 22 2c | returne|d %d\n",|
|00002240| 20 70 72 6f 67 6e 61 6d | 65 2c 20 77 6f 72 64 2c | prognam|e, word,|
|00002250| 20 69 29 3b 0a 58 20 20 | 20 20 20 20 7d 0a 58 20 | i);.X | }.X |
|00002260| 20 20 20 7d 0a 58 20 20 | 72 65 74 75 72 6e 20 30 | }.X |return 0|
|00002270| 3b 0a 58 20 20 7d 0a 45 | 4e 44 5f 4f 46 5f 74 65 |;.X }.E|ND_OF_te|
|00002280| 73 74 2e 63 0a 69 66 20 | 74 65 73 74 20 38 38 32 |st.c.if |test 882|
|00002290| 20 2d 6e 65 20 60 77 63 | 20 2d 63 20 3c 74 65 73 | -ne `wc| -c <tes|
|000022a0| 74 2e 63 60 3b 20 74 68 | 65 6e 0a 20 20 20 20 65 |t.c`; th|en. e|
|000022b0| 63 68 6f 20 73 68 61 72 | 3a 20 5c 22 74 65 73 74 |cho shar|: \"test|
|000022c0| 2e 63 5c 22 20 75 6e 70 | 61 63 6b 65 64 20 77 69 |.c\" unp|acked wi|
|000022d0| 74 68 20 77 72 6f 6e 67 | 20 73 69 7a 65 21 0a 66 |th wrong| size!.f|
|000022e0| 69 0a 23 20 65 6e 64 20 | 6f 66 20 6f 76 65 72 77 |i.# end |of overw|
|000022f0| 72 69 74 69 6e 67 20 63 | 68 65 63 6b 0a 66 69 0a |riting c|heck.fi.|
|00002300| 69 66 20 74 65 73 74 20 | 2d 66 20 74 65 73 74 63 |if test |-f testc|
|00002310| 6d 64 2e 63 20 2d 61 20 | 22 24 7b 31 7d 22 20 21 |md.c -a |"${1}" !|
|00002320| 3d 20 22 2d 63 22 20 3b | 20 74 68 65 6e 20 0a 20 |= "-c" ;| then . |
|00002330| 20 65 63 68 6f 20 73 68 | 61 72 3a 20 57 69 6c 6c | echo sh|ar: Will|
|00002340| 20 6e 6f 74 20 6f 76 65 | 72 2d 77 72 69 74 65 20 | not ove|r-write |
|00002350| 65 78 69 73 74 69 6e 67 | 20 66 69 6c 65 20 5c 22 |existing| file \"|
|00002360| 74 65 73 74 63 6d 64 2e | 63 5c 22 0a 65 6c 73 65 |testcmd.|c\".else|
|00002370| 0a 65 63 68 6f 20 73 68 | 61 72 3a 20 45 78 74 72 |.echo sh|ar: Extr|
|00002380| 61 63 74 69 6e 67 20 5c | 22 74 65 73 74 63 6d 64 |acting \|"testcmd|
|00002390| 2e 63 5c 22 20 5c 28 33 | 32 38 20 63 68 61 72 61 |.c\" \(3|28 chara|
|000023a0| 63 74 65 72 73 5c 29 0a | 73 65 64 20 22 73 2f 5e |cters\).|sed "s/^|
|000023b0| 58 2f 2f 22 20 3e 74 65 | 73 74 63 6d 64 2e 63 20 |X//" >te|stcmd.c |
|000023c0| 3c 3c 27 45 4e 44 5f 4f | 46 5f 74 65 73 74 63 6d |<<'END_O|F_testcm|
|000023d0| 64 2e 63 27 0a 58 23 69 | 6e 63 6c 75 64 65 20 3c |d.c'.X#i|nclude <|
|000023e0| 73 74 72 65 61 6d 2e 68 | 3e 0a 58 0a 58 69 6e 74 |stream.h|>.X.Xint|
|000023f0| 20 61 28 63 6f 6e 73 74 | 20 63 68 61 72 20 2a 73 | a(const| char *s|
|00002400| 29 0a 58 20 20 7b 0a 58 | 20 20 63 6f 75 74 20 3c |).X {.X| cout <|
|00002410| 3c 20 66 6f 72 6d 28 22 | 61 3a 20 25 73 5c 6e 22 |< form("|a: %s\n"|
|00002420| 2c 20 73 29 3b 0a 58 20 | 20 72 65 74 75 72 6e 20 |, s);.X | return |
|00002430| 30 3b 0a 58 20 20 7d 0a | 58 0a 58 69 6e 74 20 62 |0;.X }.|X.Xint b|
|00002440| 28 63 6f 6e 73 74 20 63 | 68 61 72 20 2a 73 29 0a |(const c|har *s).|
|00002450| 58 20 20 7b 0a 58 20 20 | 63 6f 75 74 20 3c 3c 20 |X {.X |cout << |
|00002460| 66 6f 72 6d 28 22 62 3a | 20 25 73 5c 6e 22 2c 20 |form("b:| %s\n", |
|00002470| 73 29 3b 0a 58 20 20 72 | 65 74 75 72 6e 20 30 3b |s);.X r|eturn 0;|
|00002480| 0a 58 20 20 7d 0a 58 0a | 58 69 6e 74 20 63 28 63 |.X }.X.|Xint c(c|
|00002490| 6f 6e 73 74 20 63 68 61 | 72 20 2a 73 29 0a 58 20 |onst cha|r *s).X |
|000024a0| 20 7b 0a 58 20 20 63 6f | 75 74 20 3c 3c 20 66 6f | {.X co|ut << fo|
|000024b0| 72 6d 28 22 63 3a 20 25 | 73 5c 6e 22 2c 20 73 29 |rm("c: %|s\n", s)|
|000024c0| 3b 0a 58 20 20 72 65 74 | 75 72 6e 20 30 3b 0a 58 |;.X ret|urn 0;.X|
|000024d0| 20 20 7d 0a 58 0a 58 69 | 6e 74 20 6f 6f 70 73 28 | }.X.Xi|nt oops(|
|000024e0| 63 6f 6e 73 74 20 63 68 | 61 72 20 2a 73 29 0a 58 |const ch|ar *s).X|
|000024f0| 20 20 7b 0a 58 20 20 63 | 6f 75 74 20 3c 3c 20 66 | {.X c|out << f|
|00002500| 6f 72 6d 28 22 63 6f 6d | 6d 61 6e 64 20 25 73 20 |orm("com|mand %s |
|00002510| 75 6e 61 76 61 69 6c 61 | 62 6c 65 5c 6e 22 2c 20 |unavaila|ble\n", |
|00002520| 73 29 3b 0a 58 20 20 72 | 65 74 75 72 6e 20 30 3b |s);.X r|eturn 0;|
|00002530| 0a 58 20 20 7d 0a 45 4e | 44 5f 4f 46 5f 74 65 73 |.X }.EN|D_OF_tes|
|00002540| 74 63 6d 64 2e 63 0a 69 | 66 20 74 65 73 74 20 33 |tcmd.c.i|f test 3|
|00002550| 32 38 20 2d 6e 65 20 60 | 77 63 20 2d 63 20 3c 74 |28 -ne `|wc -c <t|
|00002560| 65 73 74 63 6d 64 2e 63 | 60 3b 20 74 68 65 6e 0a |estcmd.c|`; then.|
|00002570| 20 20 20 20 65 63 68 6f | 20 73 68 61 72 3a 20 5c | echo| shar: \|
|00002580| 22 74 65 73 74 63 6d 64 | 2e 63 5c 22 20 75 6e 70 |"testcmd|.c\" unp|
|00002590| 61 63 6b 65 64 20 77 69 | 74 68 20 77 72 6f 6e 67 |acked wi|th wrong|
|000025a0| 20 73 69 7a 65 21 0a 66 | 69 0a 23 20 65 6e 64 20 | size!.f|i.# end |
|000025b0| 6f 66 20 6f 76 65 72 77 | 72 69 74 69 6e 67 20 63 |of overw|riting c|
|000025c0| 68 65 63 6b 0a 66 69 0a | 69 66 20 74 65 73 74 20 |heck.fi.|if test |
|000025d0| 2d 66 20 74 65 73 74 68 | 65 6c 70 2e 63 20 2d 61 |-f testh|elp.c -a|
|000025e0| 20 22 24 7b 31 7d 22 20 | 21 3d 20 22 2d 63 22 20 | "${1}" |!= "-c" |
|000025f0| 3b 20 74 68 65 6e 20 0a | 20 20 65 63 68 6f 20 73 |; then .| echo s|
|00002600| 68 61 72 3a 20 57 69 6c | 6c 20 6e 6f 74 20 6f 76 |har: Wil|l not ov|
|00002610| 65 72 2d 77 72 69 74 65 | 20 65 78 69 73 74 69 6e |er-write| existin|
|00002620| 67 20 66 69 6c 65 20 5c | 22 74 65 73 74 68 65 6c |g file \|"testhel|
|00002630| 70 2e 63 5c 22 0a 65 6c | 73 65 0a 65 63 68 6f 20 |p.c\".el|se.echo |
|00002640| 73 68 61 72 3a 20 45 78 | 74 72 61 63 74 69 6e 67 |shar: Ex|tracting|
|00002650| 20 5c 22 74 65 73 74 68 | 65 6c 70 2e 63 5c 22 20 | \"testh|elp.c\" |
|00002660| 5c 28 33 34 31 20 63 68 | 61 72 61 63 74 65 72 73 |\(341 ch|aracters|
|00002670| 5c 29 0a 73 65 64 20 22 | 73 2f 5e 58 2f 2f 22 20 |\).sed "|s/^X//" |
|00002680| 3e 74 65 73 74 68 65 6c | 70 2e 63 20 3c 3c 27 45 |>testhel|p.c <<'E|
|00002690| 4e 44 5f 4f 46 5f 74 65 | 73 74 68 65 6c 70 2e 63 |ND_OF_te|sthelp.c|
|000026a0| 27 0a 58 23 69 6e 63 6c | 75 64 65 20 3c 73 74 72 |'.X#incl|ude <str|
|000026b0| 65 61 6d 2e 68 3e 0a 58 | 23 69 6e 63 6c 75 64 65 |eam.h>.X|#include|
|000026c0| 20 22 6c 6f 6f 6b 75 70 | 2e 68 22 0a 58 0a 58 65 | "lookup|.h".X.Xe|
|000026d0| 78 74 65 72 6e 20 65 6e | 74 72 79 20 6c 69 73 74 |xtern en|try list|
|000026e0| 5b 5d 3b 0a 58 0a 58 69 | 6e 74 20 68 65 6c 70 28 |[];.X.Xi|nt help(|
|000026f0| 63 6f 6e 73 74 20 63 68 | 61 72 20 2a 73 29 0a 58 |const ch|ar *s).X|
|00002700| 20 20 7b 0a 58 20 20 65 | 6e 74 72 79 20 2a 74 20 | {.X e|ntry *t |
|00002710| 3d 20 6c 69 73 74 3b 0a | 58 0a 58 20 20 28 76 6f |= list;.|X.X (vo|
|00002720| 69 64 29 20 73 3b 20 2f | 2f 20 22 75 73 65 22 20 |id) s; /|/ "use" |
|00002730| 73 20 73 6f 20 74 68 61 | 74 20 43 43 20 77 6f 6e |s so tha|t CC won|
|00002740| 27 74 20 63 6f 6d 70 6c | 61 69 6e 0a 58 20 20 63 |'t compl|ain.X c|
|00002750| 6f 75 74 20 3c 3c 20 22 | 41 76 61 69 6c 61 62 6c |out << "|Availabl|
|00002760| 65 20 63 6f 6d 6d 61 6e | 64 73 3a 5c 6e 5c 6e 22 |e comman|ds:\n\n"|
|00002770| 3b 0a 58 20 20 63 6f 75 | 74 20 3c 3c 20 22 71 75 |;.X cou|t << "qu|
|00002780| 69 74 5c 74 22 3b 0a 58 | 0a 58 20 20 66 6f 72 28 |it\t";.X|.X for(|
|00002790| 69 6e 74 20 6d 61 78 3d | 31 2b 69 6e 74 28 28 74 |int max=|1+int((t|
|000027a0| 2b 2b 29 2d 3e 6e 61 6d | 65 29 3b 20 74 2d 6c 69 |++)->nam|e); t-li|
|000027b0| 73 74 20 3c 20 6d 61 78 | 3b 20 74 2b 2b 29 0a 58 |st < max|; t++).X|
|000027c0| 20 20 20 20 63 6f 75 74 | 20 3c 3c 20 66 6f 72 6d | cout| << form|
|000027d0| 28 22 25 73 5c 74 22 2c | 20 74 2d 3e 6e 61 6d 65 |("%s\t",| t->name|
|000027e0| 29 3b 0a 58 0a 58 20 20 | 63 6f 75 74 2e 70 75 74 |);.X.X |cout.put|
|000027f0| 28 27 5c 6e 27 29 3b 0a | 58 20 20 72 65 74 75 72 |('\n');.|X retur|
|00002800| 6e 20 30 3b 0a 58 20 20 | 7d 0a 45 4e 44 5f 4f 46 |n 0;.X |}.END_OF|
|00002810| 5f 74 65 73 74 68 65 6c | 70 2e 63 0a 69 66 20 74 |_testhel|p.c.if t|
|00002820| 65 73 74 20 33 34 31 20 | 2d 6e 65 20 60 77 63 20 |est 341 |-ne `wc |
|00002830| 2d 63 20 3c 74 65 73 74 | 68 65 6c 70 2e 63 60 3b |-c <test|help.c`;|
|00002840| 20 74 68 65 6e 0a 20 20 | 20 20 65 63 68 6f 20 73 | then. | echo s|
|00002850| 68 61 72 3a 20 5c 22 74 | 65 73 74 68 65 6c 70 2e |har: \"t|esthelp.|
|00002860| 63 5c 22 20 75 6e 70 61 | 63 6b 65 64 20 77 69 74 |c\" unpa|cked wit|
|00002870| 68 20 77 72 6f 6e 67 20 | 73 69 7a 65 21 0a 66 69 |h wrong |size!.fi|
|00002880| 0a 23 20 65 6e 64 20 6f | 66 20 6f 76 65 72 77 72 |.# end o|f overwr|
|00002890| 69 74 69 6e 67 20 63 68 | 65 63 6b 0a 66 69 0a 65 |iting ch|eck.fi.e|
|000028a0| 63 68 6f 20 73 68 61 72 | 3a 20 45 6e 64 20 6f 66 |cho shar|: End of|
|000028b0| 20 73 68 65 6c 6c 20 61 | 72 63 68 69 76 65 2e 0a | shell a|rchive..|
|000028c0| 65 78 69 74 20 30 0a 2d | 2d 20 0a 52 65 69 64 20 |exit 0.-|- .Reid |
|000028d0| 45 6c 6c 69 73 2c 20 67 | 65 61 63 6c 69 62 21 72 |Ellis, g|eaclib!r|
|000028e0| 61 65 40 67 65 61 63 2e | 75 75 63 70 2c 20 72 61 |ae@geac.|uucp, ra|
|000028f0| 65 40 67 65 61 63 6c 69 | 62 2e 75 75 63 70 20 5b |e@geacli|b.uucp [|
|00002900| 69 66 20 79 6f 75 27 72 | 65 20 6c 75 63 6b 79 5d |if you'r|e lucky]|
|00002910| 0a 0a | |.. | |
+--------+-------------------------+-------------------------+--------+--------+