home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8710 / 17 < prev    next >
SHell self-extracting ARchive  |  1990-07-13  |  20.7 KB

view JSON data     |     view as text     |     open on a Mac     |     open on a PC

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

You can browse this item here: 17

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert Newsgroup Content (archive/news) magic Supported
100% dexvert SHell self-extracting ARchive (archive/shar) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file news text default
99% file C source text default
98% file C source, ASCII text default
100% checkBytes Printable ASCII default
100% dexmagic PrintFox/Pagefox WEAK default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/329 Shell Archive Format default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime message/news default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 50 61 74 68 3a 20 75 75 | 6e 65 74 21 68 75 73 63 |Path: uu|net!husc|
|00000010| 36 21 68 61 6f 21 61 6d | 65 73 21 61 75 72 6f 72 |6!hao!am|es!auror|
|00000020| 61 21 6c 61 62 72 65 61 | 21 64 65 63 77 72 6c 21 |a!labrea|!decwrl!|
|00000030| 70 79 72 61 6d 69 64 21 | 75 63 63 62 61 21 68 61 |pyramid!|uccba!ha|
|00000040| 6c 21 6e 63 6f 61 73 74 | 21 61 6c 6c 62 65 72 79 |l!ncoast|!allbery|
|00000050| 0a 46 72 6f 6d 3a 20 73 | 69 6d 6f 6e 40 69 74 73 |.From: s|imon@its|
|00000060| 36 33 62 2e 65 64 2e 61 | 63 2e 75 6b 20 28 53 69 |63b.ed.a|c.uk (Si|
|00000070| 6d 6f 6e 20 42 72 6f 77 | 6e 29 0a 4e 65 77 73 67 |mon Brow|n).Newsg|
|00000080| 72 6f 75 70 73 3a 20 63 | 6f 6d 70 2e 73 6f 75 72 |roups: c|omp.sour|
|00000090| 63 65 73 2e 6d 69 73 63 | 0a 53 75 62 6a 65 63 74 |ces.misc|.Subject|
|000000a0| 3a 20 52 65 3a 20 65 20 | 2d 20 61 20 66 72 69 65 |: Re: e |- a frie|
|000000b0| 6e 64 6c 79 20 69 6e 74 | 65 72 66 61 63 65 20 74 |ndly int|erface t|
|000000c0| 6f 20 76 69 0a 4d 65 73 | 73 61 67 65 2d 49 44 3a |o vi.Mes|sage-ID:|
|000000d0| 20 3c 34 39 33 32 40 6e | 63 6f 61 73 74 2e 55 55 | <4932@n|coast.UU|
|000000e0| 43 50 3e 0a 44 61 74 65 | 3a 20 32 34 20 4f 63 74 |CP>.Date|: 24 Oct|
|000000f0| 20 38 37 20 30 30 3a 34 | 34 3a 33 34 20 47 4d 54 | 87 00:4|4:34 GMT|
|00000100| 0a 53 65 6e 64 65 72 3a | 20 61 6c 6c 62 65 72 79 |.Sender:| allbery|
|00000110| 40 6e 63 6f 61 73 74 2e | 55 55 43 50 0a 4f 72 67 |@ncoast.|UUCP.Org|
|00000120| 61 6e 69 7a 61 74 69 6f | 6e 3a 20 43 6f 6d 70 75 |anizatio|n: Compu|
|00000130| 74 65 72 20 53 63 69 65 | 6e 63 65 20 44 65 70 61 |ter Scie|nce Depa|
|00000140| 72 74 6d 65 6e 74 2c 20 | 45 64 69 6e 62 75 72 67 |rtment, |Edinburg|
|00000150| 68 20 55 6e 69 76 65 72 | 73 69 74 79 0a 4c 69 6e |h Univer|sity.Lin|
|00000160| 65 73 3a 20 39 38 39 0a | 41 70 70 72 6f 76 65 64 |es: 989.|Approved|
|00000170| 3a 20 61 6c 6c 62 65 72 | 79 40 6e 63 6f 61 73 74 |: allber|y@ncoast|
|00000180| 2e 55 55 43 50 0a 58 2d | 41 72 63 68 69 76 65 3a |.UUCP.X-|Archive:|
|00000190| 20 63 6f 6d 70 2e 73 6f | 75 72 63 65 73 2e 6d 69 | comp.so|urces.mi|
|000001a0| 73 63 2f 38 37 31 30 2f | 31 37 0a 0a 48 65 72 65 |sc/8710/|17..Here|
|000001b0| 27 73 20 61 20 63 6c 65 | 61 6e 65 64 2d 75 70 20 |'s a cle|aned-up |
|000001c0| 28 49 20 68 6f 70 65 29 | 20 76 65 72 73 69 6f 6e |(I hope)| version|
|000001d0| 20 6f 66 20 65 20 2d 0a | 09 6f 20 50 6f 72 74 65 | of e -.|.o Porte|
|000001e0| 64 20 74 6f 20 53 79 73 | 74 65 6d 20 56 2e 0a 09 |d to Sys|tem V...|
|000001f0| 6f 20 50 75 74 73 20 68 | 69 73 74 6f 72 79 20 69 |o Puts h|istory i|
|00000200| 6e 20 74 68 65 20 63 6f | 72 72 65 63 74 20 66 69 |n the co|rrect fi|
|00000210| 6c 65 20 65 76 65 6e 20 | 69 66 20 79 6f 75 20 74 |le even |if you t|
|00000220| 72 79 20 74 6f 20 65 64 | 69 74 0a 09 20 20 66 69 |ry to ed|it.. fi|
|00000230| 6c 65 73 20 6e 6f 74 20 | 69 6e 20 74 68 65 20 63 |les not |in the c|
|00000240| 75 72 72 65 6e 74 20 64 | 69 72 65 63 74 6f 72 79 |urrent d|irectory|
|00000250| 2e 0a 09 6f 20 22 65 20 | 2d 22 20 61 6e 64 20 22 |...o "e |-" and "|
|00000260| 65 20 2e 22 20 75 73 65 | 20 74 68 65 20 73 61 6d |e ." use| the sam|
|00000270| 65 20 6e 75 6d 62 65 72 | 69 6e 67 20 73 63 68 65 |e number|ing sche|
|00000280| 6d 65 2e 0a 09 6f 20 4d | 75 6c 74 69 70 6c 65 20 |me...o M|ultiple |
|00000290| 66 69 6c 65 2d 65 6e 74 | 72 69 65 73 20 69 6e 20 |file-ent|ries in |
|000002a0| 68 69 73 74 6f 72 79 2d | 66 69 6c 65 73 20 6e 6f |history-|files no|
|000002b0| 20 6c 6f 6e 67 65 72 20 | 6f 63 63 75 72 2e 0a 09 | longer |occur...|
|000002c0| 6f 20 55 73 65 73 20 24 | 45 44 49 54 4f 52 20 69 |o Uses $|EDITOR i|
|000002d0| 6e 73 74 65 61 64 20 6f | 66 20 61 6c 77 61 79 73 |nstead o|f always|
|000002e0| 20 75 73 69 6e 67 20 22 | 76 69 22 2e 0a 0a 57 61 | using "|vi"...Wa|
|000002f0| 72 6e 69 6e 67 3a 20 74 | 68 69 73 20 63 68 61 6e |rning: t|his chan|
|00000300| 67 65 64 20 76 65 72 73 | 69 6f 6e 20 68 61 73 20 |ged vers|ion has |
|00000310| 6e 6f 74 20 62 65 65 6e | 20 74 65 73 74 65 64 20 |not been| tested |
|00000320| 75 6e 64 65 72 20 42 53 | 44 20 28 63 6f 73 20 49 |under BS|D (cos I|
|00000330| 20 77 61 73 0a 74 6f 6f | 20 6c 61 7a 79 29 2e 0a | was.too| lazy)..|
|00000340| 0a 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |.-------|--------|
|00000350| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 20 63 75 74 20 68 65 |--------|- cut he|
|00000360| 72 65 20 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |re -----|--------|
|00000370| 2d 2d 2d 2d 2d 2d 0a 23 | 21 20 2f 62 69 6e 2f 73 |------.#|! /bin/s|
|00000380| 68 0a 23 20 54 68 69 73 | 20 69 73 20 61 20 73 68 |h.# This| is a sh|
|00000390| 65 6c 6c 20 61 72 63 68 | 69 76 65 2c 20 6d 65 61 |ell arch|ive, mea|
|000003a0| 6e 69 6e 67 3a 0a 23 20 | 31 2e 20 52 65 6d 6f 76 |ning:.# |1. Remov|
|000003b0| 65 20 65 76 65 72 79 74 | 68 69 6e 67 20 61 62 6f |e everyt|hing abo|
|000003c0| 76 65 20 74 68 65 20 23 | 21 20 2f 62 69 6e 2f 73 |ve the #|! /bin/s|
|000003d0| 68 20 6c 69 6e 65 2e 0a | 23 20 32 2e 20 53 61 76 |h line..|# 2. Sav|
|000003e0| 65 20 74 68 65 20 72 65 | 73 75 6c 74 69 6e 67 20 |e the re|sulting |
|000003f0| 74 65 78 74 20 69 6e 20 | 61 20 66 69 6c 65 2e 0a |text in |a file..|
|00000400| 23 20 33 2e 20 45 78 65 | 63 75 74 65 20 74 68 65 |# 3. Exe|cute the|
|00000410| 20 66 69 6c 65 20 77 69 | 74 68 20 2f 62 69 6e 2f | file wi|th /bin/|
|00000420| 73 68 20 28 6e 6f 74 20 | 63 73 68 29 20 74 6f 20 |sh (not |csh) to |
|00000430| 63 72 65 61 74 65 3a 0a | 23 09 65 2e 63 0a 23 20 |create:.|#.e.c.# |
|00000440| 54 68 69 73 20 61 72 63 | 68 69 76 65 20 63 72 65 |This arc|hive cre|
|00000450| 61 74 65 64 3a 20 54 68 | 75 20 4f 63 74 20 31 35 |ated: Th|u Oct 15|
|00000460| 20 32 30 3a 31 37 3a 33 | 37 20 31 39 38 37 0a 23 | 20:17:3|7 1987.#|
|00000470| 20 42 79 3a 09 53 69 6d | 6f 6e 20 42 72 6f 77 6e | By:.Sim|on Brown|
|00000480| 20 28 43 6f 6d 70 75 74 | 65 72 20 53 63 69 65 6e | (Comput|er Scien|
|00000490| 63 65 20 44 65 70 61 72 | 74 6d 65 6e 74 2c 20 45 |ce Depar|tment, E|
|000004a0| 64 69 6e 62 75 72 67 68 | 20 55 6e 69 76 65 72 73 |dinburgh| Univers|
|000004b0| 69 74 79 29 0a 65 78 70 | 6f 72 74 20 50 41 54 48 |ity).exp|ort PATH|
|000004c0| 3b 20 50 41 54 48 3d 2f | 62 69 6e 3a 2f 75 73 72 |; PATH=/|bin:/usr|
|000004d0| 2f 62 69 6e 3a 24 50 41 | 54 48 0a 65 63 68 6f 20 |/bin:$PA|TH.echo |
|000004e0| 73 68 61 72 3a 20 22 65 | 78 74 72 61 63 74 69 6e |shar: "e|xtractin|
|000004f0| 67 20 27 65 2e 63 27 22 | 20 27 28 31 39 32 34 34 |g 'e.c'"| '(19244|
|00000500| 20 63 68 61 72 61 63 74 | 65 72 73 29 27 0a 69 66 | charact|ers)'.if|
|00000510| 20 74 65 73 74 20 2d 66 | 20 27 65 2e 63 27 0a 74 | test -f| 'e.c'.t|
|00000520| 68 65 6e 0a 09 65 63 68 | 6f 20 73 68 61 72 3a 20 |hen..ech|o shar: |
|00000530| 22 77 69 6c 6c 20 6e 6f | 74 20 6f 76 65 72 2d 77 |"will no|t over-w|
|00000540| 72 69 74 65 20 65 78 69 | 73 74 69 6e 67 20 66 69 |rite exi|sting fi|
|00000550| 6c 65 20 27 65 2e 63 27 | 22 0a 65 6c 73 65 0a 63 |le 'e.c'|".else.c|
|00000560| 61 74 20 3c 3c 20 5c 53 | 48 41 52 5f 45 4f 46 20 |at << \S|HAR_EOF |
|00000570| 3e 20 27 65 2e 63 27 0a | 2f 2a 0a 20 2a 20 65 2e |> 'e.c'.|/*. * e.|
|00000580| 63 20 2d 20 61 20 66 72 | 69 65 6e 64 6c 79 20 69 |c - a fr|iendly i|
|00000590| 6e 74 65 72 66 61 63 65 | 20 74 6f 20 76 69 0a 20 |nterface| to vi. |
|000005a0| 2a 0a 20 2a 20 54 65 72 | 72 79 20 4a 6f 6e 65 73 |*. * Ter|ry Jones|
|000005b0| 20 20 20 20 7b 69 68 6e | 70 34 2c 61 6c 6c 65 67 | {ihn|p4,alleg|
|000005c0| 72 61 2c 64 65 63 76 61 | 78 2c 75 74 7a 6f 6f 2c |ra,decva|x,utzoo,|
|000005d0| 75 74 63 73 72 69 7d 21 | 77 61 74 6d 61 74 68 21 |utcsri}!|watmath!|
|000005e0| 77 61 74 64 72 61 67 6f | 6e 21 74 63 6a 6f 6e 65 |watdrago|n!tcjone|
|000005f0| 73 0a 20 2a 20 44 65 70 | 61 72 74 6d 65 6e 74 20 |s. * Dep|artment |
|00000600| 6f 66 20 43 6f 6d 70 75 | 74 65 72 20 53 63 69 65 |of Compu|ter Scie|
|00000610| 6e 63 65 0a 20 2a 20 55 | 6e 69 76 65 72 73 69 74 |nce. * U|niversit|
|00000620| 79 20 6f 66 20 57 61 74 | 65 72 6c 6f 6f 0a 20 2a |y of Wat|erloo. *|
|00000630| 20 57 61 74 65 72 6c 6f | 6f 2c 20 4f 6e 74 61 72 | Waterlo|o, Ontar|
|00000640| 69 6f 2c 20 43 61 6e 61 | 64 61 2e 20 4e 32 4c 20 |io, Cana|da. N2L |
|00000650| 33 47 31 0a 20 2a 0a 20 | 2a 0a 20 2a 20 62 65 73 |3G1. *. |*. * bes|
|00000660| 74 20 76 69 27 65 64 20 | 77 69 74 68 20 74 73 3d |t vi'ed |with ts=|
|00000670| 34 20 73 77 3d 34 0a 20 | 2a 20 74 6f 20 63 6f 6d |4 sw=4. |* to com|
|00000680| 70 69 6c 65 3a 20 63 63 | 20 2d 6f 20 65 20 2d 4f |pile: cc| -o e -O|
|00000690| 20 65 2e 63 0a 20 2a 2f | 0a 0a 23 69 6e 63 6c 75 | e.c. */|..#inclu|
|000006a0| 64 65 20 3c 73 74 64 69 | 6f 2e 68 3e 0a 23 69 6e |de <stdi|o.h>.#in|
|000006b0| 63 6c 75 64 65 20 3c 73 | 79 73 2f 74 79 70 65 73 |clude <s|ys/types|
|000006c0| 2e 68 3e 0a 23 69 6e 63 | 6c 75 64 65 20 3c 73 79 |.h>.#inc|lude <sy|
|000006d0| 73 2f 73 74 61 74 2e 68 | 3e 0a 23 69 6e 63 6c 75 |s/stat.h|>.#inclu|
|000006e0| 64 65 20 3c 73 79 73 2f | 66 69 6c 65 2e 68 3e 0a |de <sys/|file.h>.|
|000006f0| 0a 23 69 66 64 65 66 20 | 73 79 73 56 0a 23 20 20 |.#ifdef |sysV.# |
|00000700| 69 66 64 65 66 20 47 45 | 43 0a 23 20 20 20 20 69 |ifdef GE|C.# i|
|00000710| 6e 63 6c 75 64 65 20 3c | 6c 6f 63 61 6c 2f 6e 64 |nclude <|local/nd|
|00000720| 69 72 2e 68 3e 0a 23 20 | 20 65 6c 73 65 0a 23 20 |ir.h>.# | else.# |
|00000730| 20 20 20 69 6e 63 6c 75 | 64 65 20 3c 6e 64 69 72 | inclu|de <ndir|
|00000740| 2e 68 3e 0a 23 20 20 65 | 6e 64 69 66 0a 23 20 20 |.h>.# e|ndif.# |
|00000750| 69 6e 63 6c 75 64 65 20 | 3c 74 65 72 6d 69 6f 2e |include |<termio.|
|00000760| 68 3e 0a 23 20 20 69 6e | 63 6c 75 64 65 20 3c 73 |h>.# in|clude <s|
|00000770| 74 72 69 6e 67 2e 68 3e | 0a 23 20 20 69 6e 63 6c |tring.h>|.# incl|
|00000780| 75 64 65 20 3c 66 63 6e | 74 6c 2e 68 3e 0a 23 65 |ude <fcn|tl.h>.#e|
|00000790| 6c 73 65 0a 23 20 20 69 | 6e 63 6c 75 64 65 20 3c |lse.# i|nclude <|
|000007a0| 73 79 73 2f 64 69 72 2e | 68 3e 0a 23 20 20 69 66 |sys/dir.|h>.# if|
|000007b0| 64 65 66 20 4e 46 53 0a | 23 20 20 20 20 69 6e 63 |def NFS.|# inc|
|000007c0| 6c 75 64 65 20 3c 75 66 | 73 2f 69 6e 6f 64 65 2e |lude <uf|s/inode.|
|000007d0| 68 3e 0a 23 20 20 65 6c | 73 65 0a 23 20 20 20 20 |h>.# el|se.# |
|000007e0| 69 6e 63 6c 75 64 65 20 | 3c 73 79 73 2f 69 6e 6f |include |<sys/ino|
|000007f0| 64 65 2e 68 3e 0a 23 20 | 20 65 6e 64 69 66 0a 23 |de.h>.# | endif.#|
|00000800| 20 20 69 6e 63 6c 75 64 | 65 20 3c 73 67 74 74 79 | includ|e <sgtty|
|00000810| 2e 68 3e 0a 23 20 20 69 | 6e 63 6c 75 64 65 20 3c |.h>.# i|nclude <|
|00000820| 73 74 72 69 6e 67 73 2e | 68 3e 0a 23 65 6e 64 69 |strings.|h>.#endi|
|00000830| 66 20 73 79 73 56 0a 0a | 23 69 6e 63 6c 75 64 65 |f sysV..|#include|
|00000840| 20 3c 73 69 67 6e 61 6c | 2e 68 3e 0a 23 69 6e 63 | <signal|.h>.#inc|
|00000850| 6c 75 64 65 20 3c 63 74 | 79 70 65 2e 68 3e 0a 0a |lude <ct|ype.h>..|
|00000860| 23 69 66 64 65 66 20 73 | 79 73 56 0a 23 20 20 64 |#ifdef s|ysV.# d|
|00000870| 65 66 69 6e 65 20 56 49 | 20 22 2f 75 73 72 2f 62 |efine VI| "/usr/b|
|00000880| 69 6e 2f 76 69 22 0a 23 | 20 20 64 65 66 69 6e 65 |in/vi".#| define|
|00000890| 20 69 6e 64 65 78 20 73 | 74 72 63 68 72 0a 23 20 | index s|trchr.# |
|000008a0| 20 64 65 66 69 6e 65 20 | 72 69 6e 64 65 78 20 73 | define |rindex s|
|000008b0| 74 72 72 63 68 72 0a 23 | 65 6c 73 65 0a 23 20 20 |trrchr.#|else.# |
|000008c0| 64 65 66 69 6e 65 20 56 | 49 20 22 2f 75 73 72 2f |define V|I "/usr/|
|000008d0| 75 63 62 2f 76 69 22 0a | 23 65 6e 64 69 66 20 73 |ucb/vi".|#endif s|
|000008e0| 79 73 56 0a 0a 23 69 66 | 6e 64 65 66 20 4c 5f 53 |ysV..#if|ndef L_S|
|000008f0| 45 54 0a 23 20 64 65 66 | 69 6e 65 20 4c 5f 53 45 |ET.# def|ine L_SE|
|00000900| 54 20 30 0a 23 65 6e 64 | 69 66 0a 23 69 66 6e 64 |T 0.#end|if.#ifnd|
|00000910| 65 66 20 49 52 45 41 44 | 0a 23 20 64 65 66 69 6e |ef IREAD|.# defin|
|00000920| 65 20 49 52 45 41 44 09 | 30 34 30 30 0a 23 20 64 |e IREAD.|0400.# d|
|00000930| 65 66 69 6e 65 20 49 57 | 52 49 54 45 09 30 32 30 |efine IW|RITE.020|
|00000940| 30 0a 23 65 6e 64 69 66 | 0a 0a 23 64 65 66 69 6e |0.#endif|..#defin|
|00000950| 65 20 48 49 53 54 20 22 | 2e 65 22 0a 23 64 65 66 |e HIST "|.e".#def|
|00000960| 69 6e 65 20 48 49 53 54 | 5f 4c 49 4e 45 53 20 38 |ine HIST|_LINES 8|
|00000970| 0a 23 64 65 66 69 6e 65 | 20 48 49 53 54 5f 43 48 |.#define| HIST_CH|
|00000980| 41 52 53 20 35 31 32 0a | 23 64 65 66 69 6e 65 20 |ARS 512.|#define |
|00000990| 41 52 47 5f 43 48 41 52 | 53 20 31 30 30 0a 23 64 |ARG_CHAR|S 100.#d|
|000009a0| 65 66 69 6e 65 20 4d 41 | 58 5f 41 52 47 53 20 31 |efine MA|X_ARGS 1|
|000009b0| 30 0a 23 64 65 66 69 6e | 65 20 52 55 42 4f 55 54 |0.#defin|e RUBOUT|
|000009c0| 20 27 5c 31 37 37 27 0a | 23 64 65 66 69 6e 65 20 | '\177'.|#define |
|000009d0| 48 46 49 4c 45 4c 45 4e | 20 35 31 32 0a 0a 63 68 |HFILELEN| 512..ch|
|000009e0| 61 72 20 68 69 73 74 6f | 72 79 5b 48 49 53 54 5f |ar histo|ry[HIST_|
|000009f0| 43 48 41 52 53 5d 3b 0a | 63 68 61 72 20 61 72 67 |CHARS];.|char arg|
|00000a00| 5b 41 52 47 5f 43 48 41 | 52 53 5d 3b 0a 63 68 61 |[ARG_CHA|RS];.cha|
|00000a10| 72 20 2a 68 69 73 74 5b | 48 49 53 54 5f 4c 49 4e |r *hist[|HIST_LIN|
|00000a20| 45 53 5d 3b 0a 63 68 61 | 72 20 74 65 6d 70 5b 48 |ES];.cha|r temp[H|
|00000a30| 49 53 54 5f 43 48 41 52 | 53 5d 3b 0a 63 68 61 72 |IST_CHAR|S];.char|
|00000a40| 20 2a 74 6d 70 5f 66 69 | 6c 65 3d 22 2e 5f 76 69 | *tmp_fi|le="._vi|
|00000a50| 68 69 73 74 58 58 58 58 | 58 58 22 3b 0a 63 68 61 |histXXXX|XX";.cha|
|00000a60| 72 20 64 6f 74 73 74 72 | 69 6e 67 5b 5d 20 3d 20 |r dotstr|ing[] = |
|00000a70| 22 2e 22 3b 0a 63 68 61 | 72 20 72 75 62 6f 75 74 |".";.cha|r rubout|
|00000a80| 20 3d 20 52 55 42 4f 55 | 54 3b 0a 0a 23 69 66 64 | = RUBOU|T;..#ifd|
|00000a90| 65 66 20 73 79 73 56 0a | 73 74 72 75 63 74 20 74 |ef sysV.|struct t|
|00000aa0| 65 72 6d 69 6f 20 6f 6c | 64 62 6c 6b 3b 0a 23 65 |ermio ol|dblk;.#e|
|00000ab0| 6c 73 65 0a 73 74 72 75 | 63 74 20 73 67 74 74 79 |lse.stru|ct sgtty|
|00000ac0| 62 20 6f 6c 64 62 6c 6b | 3b 0a 23 65 6e 64 69 66 |b oldblk|;.#endif|
|00000ad0| 20 73 79 73 56 0a 0a 69 | 6e 74 20 20 74 65 72 6d | sysV..i|nt term|
|00000ae0| 5f 6d 65 73 73 79 20 3d | 20 30 3b 0a 0a 63 68 61 |_messy =| 0;..cha|
|00000af0| 72 20 2a 67 6f 74 5f 76 | 69 28 29 3b 0a 0a 76 6f |r *got_v|i();..vo|
|00000b00| 69 64 20 0a 64 6f 5f 76 | 69 28 74 68 69 6e 67 29 |id .do_v|i(thing)|
|00000b10| 0a 63 68 61 72 20 2a 74 | 68 69 6e 67 3b 0a 7b 0a |.char *t|hing;.{.|
|00000b20| 09 2f 2a 20 73 70 6c 69 | 74 20 74 68 65 20 61 72 |./* spli|t the ar|
|00000b30| 67 75 6d 65 6e 74 73 20 | 69 6e 20 27 74 68 69 6e |guments |in 'thin|
|00000b40| 67 27 20 75 70 20 61 6e | 64 20 65 78 65 63 20 76 |g' up an|d exec v|
|00000b50| 69 20 6f 6e 20 74 68 65 | 6d 20 2a 2f 0a 09 63 68 |i on the|m */..ch|
|00000b60| 61 72 20 2a 61 72 67 73 | 5b 4d 41 58 5f 41 52 47 |ar *args|[MAX_ARG|
|00000b70| 53 5d 3b 0a 09 63 68 61 | 72 20 2a 74 68 69 73 2c |S];..cha|r *this,|
|00000b80| 2a 6e 65 78 74 3b 0a 09 | 72 65 67 69 73 74 65 72 |*next;..|register|
|00000b90| 20 69 3b 0a 09 63 68 61 | 72 20 2a 67 65 74 65 6e | i;..cha|r *geten|
|00000ba0| 76 28 29 3b 0a 0a 09 69 | 66 20 28 28 61 72 67 73 |v();...i|f ((args|
|00000bb0| 5b 30 5d 3d 67 65 74 65 | 6e 76 28 22 45 44 49 54 |[0]=gete|nv("EDIT|
|00000bc0| 4f 52 22 29 29 20 3d 3d | 20 30 29 20 61 72 67 73 |OR")) ==| 0) args|
|00000bd0| 5b 30 5d 3d 56 49 3b 0a | 09 61 72 67 73 5b 31 5d |[0]=VI;.|.args[1]|
|00000be0| 3d 74 68 69 6e 67 3b 0a | 0a 09 69 3d 31 3b 0a 09 |=thing;.|..i=1;..|
|00000bf0| 77 68 69 6c 65 20 28 2a | 74 68 69 6e 67 21 3d 27 |while (*|thing!='|
|00000c00| 5c 30 27 26 26 28 74 68 | 69 6e 67 3d 69 6e 64 65 |\0'&&(th|ing=inde|
|00000c10| 78 28 74 68 69 6e 67 2c | 27 20 27 29 29 21 3d 4e |x(thing,|' '))!=N|
|00000c20| 55 4c 4c 29 7b 0a 09 09 | 2a 74 68 69 6e 67 2b 2b |ULL){...|*thing++|
|00000c30| 3d 27 5c 30 27 3b 0a 09 | 09 69 66 20 28 2a 74 68 |='\0';..|.if (*th|
|00000c40| 69 6e 67 21 3d 27 5c 30 | 27 29 7b 0a 09 09 09 61 |ing!='\0|'){....a|
|00000c50| 72 67 73 5b 2b 2b 69 5d | 3d 74 68 69 6e 67 3b 0a |rgs[++i]|=thing;.|
|00000c60| 09 09 7d 0a 09 7d 0a 09 | 61 72 67 73 5b 2b 2b 69 |..}..}..|args[++i|
|00000c70| 5d 3d 4e 55 4c 4c 3b 0a | 09 09 0a 09 69 66 20 28 |]=NULL;.|....if (|
|00000c80| 65 78 65 63 76 70 28 61 | 72 67 73 5b 30 5d 2c 61 |execvp(a|rgs[0],a|
|00000c90| 72 67 73 29 3d 3d 2d 31 | 29 7b 0a 09 09 70 65 72 |rgs)==-1|){...per|
|00000ca0| 72 6f 72 28 61 72 67 73 | 5b 30 5d 29 3b 0a 09 09 |ror(args|[0]);...|
|00000cb0| 65 78 69 74 28 31 29 3b | 0a 09 7d 0a 7d 0a 0a 6d |exit(1);|..}.}..m|
|00000cc0| 61 69 6e 28 63 2c 76 29 | 0a 69 6e 74 20 63 3b 0a |ain(c,v)|.int c;.|
|00000cd0| 63 68 61 72 20 2a 2a 76 | 3b 0a 7b 0a 09 65 78 74 |char **v|;.{..ext|
|00000ce0| 65 72 6e 20 63 6c 65 61 | 6e 5f 75 70 28 29 3b 0a |ern clea|n_up();.|
|00000cf0| 0a 09 2f 2a 20 6d 61 6b | 65 20 73 75 72 65 20 77 |../* mak|e sure w|
|00000d00| 65 20 72 65 73 65 74 20 | 74 68 65 20 74 65 72 6d |e reset |the term|
|00000d10| 69 6e 61 6c 20 6f 6e 20 | 6f 75 72 20 77 61 79 20 |inal on |our way |
|00000d20| 6f 75 74 20 69 66 20 77 | 65 20 67 65 74 20 69 6e |out if w|e get in|
|00000d30| 74 65 72 72 75 70 74 65 | 64 20 2a 2f 0a 09 69 66 |terrupte|d */..if|
|00000d40| 20 28 73 69 67 6e 61 6c | 28 53 49 47 49 4e 54 2c | (signal|(SIGINT,|
|00000d50| 20 53 49 47 5f 49 47 4e | 29 20 21 3d 20 53 49 47 | SIG_IGN|) != SIG|
|00000d60| 5f 49 47 4e 29 7b 0a 09 | 09 73 69 67 6e 61 6c 28 |_IGN){..|.signal(|
|00000d70| 53 49 47 49 4e 54 2c 20 | 63 6c 65 61 6e 5f 75 70 |SIGINT, |clean_up|
|00000d80| 29 3b 0a 09 7d 0a 0a 09 | 73 77 69 74 63 68 20 28 |);..}...|switch (|
|00000d90| 63 29 7b 0a 09 09 63 61 | 73 65 20 31 3a 20 0a 09 |c){...ca|se 1: ..|
|00000da0| 09 09 2f 2a 20 6a 75 73 | 74 20 67 6f 20 61 6e 64 |../* jus|t go and|
|00000db0| 20 76 69 20 74 68 65 20 | 6c 61 73 74 20 66 69 6c | vi the |last fil|
|00000dc0| 65 20 74 68 61 74 20 77 | 61 73 20 76 69 27 65 64 |e that w|as vi'ed|
|00000dd0| 20 2a 2f 0a 09 09 09 6c | 61 73 74 5f 66 69 6c 65 | */....l|ast_file|
|00000de0| 28 29 3b 0a 09 09 09 64 | 6f 5f 76 69 28 61 72 67 |();....d|o_vi(arg|
|00000df0| 29 3b 0a 09 09 09 62 72 | 65 61 6b 3b 0a 09 09 0a |);....br|eak;....|
|00000e00| 09 09 63 61 73 65 20 32 | 3a 0a 09 09 09 73 77 69 |..case 2|:....swi|
|00000e10| 74 63 68 20 28 28 2a 2b | 2b 76 29 5b 30 5d 29 7b |tch ((*+|+v)[0]){|
|00000e20| 0a 09 09 09 09 63 61 73 | 65 20 27 2d 27 3a 0a 09 |.....cas|e '-':..|
|00000e30| 09 09 09 09 69 66 20 28 | 28 63 3d 28 2a 76 29 5b |....if (|(c=(*v)[|
|00000e40| 31 5d 29 3d 3d 27 5c 30 | 27 29 7b 0a 09 09 09 09 |1])=='\0|'){.....|
|00000e50| 09 09 2f 2a 20 74 68 69 | 73 20 69 73 20 61 20 73 |../* thi|s is a s|
|00000e60| 65 6c 65 63 74 20 66 72 | 6f 6d 20 68 69 73 74 6f |elect fr|om histo|
|00000e70| 72 79 2c 20 61 73 6b 20 | 77 68 61 74 20 74 68 65 |ry, ask |what the|
|00000e80| 79 20 77 61 6e 74 20 2a | 2f 0a 09 09 09 09 09 09 |y want *|/.......|
|00000e90| 61 73 6b 5f 68 69 73 74 | 28 29 3b 0a 09 09 09 09 |ask_hist|();.....|
|00000ea0| 09 09 64 6f 5f 76 69 28 | 61 72 67 29 3b 0a 09 09 |..do_vi(|arg);...|
|00000eb0| 09 09 09 7d 0a 09 09 09 | 09 09 65 6c 73 65 20 69 |...}....|..else i|
|00000ec0| 66 20 28 69 73 64 69 67 | 69 74 28 63 29 29 7b 0a |f (isdig|it(c)){.|
|00000ed0| 09 09 09 09 09 09 2f 2a | 20 67 65 74 20 74 68 65 |....../*| get the|
|00000ee0| 20 6e 74 68 20 6c 61 73 | 74 20 66 69 6c 65 20 66 | nth las|t file f|
|00000ef0| 72 6f 6d 20 74 68 65 20 | 68 69 73 74 6f 72 79 20 |rom the |history |
|00000f00| 61 6e 64 20 76 69 20 69 | 74 20 2a 2f 0a 09 09 09 |and vi i|t */....|
|00000f10| 09 09 09 6e 74 68 5f 68 | 69 73 74 28 63 2d 27 30 |...nth_h|ist(c-'0|
|00000f20| 27 29 3b 0a 09 09 09 09 | 09 09 64 6f 5f 76 69 28 |');.....|..do_vi(|
|00000f30| 61 72 67 29 3b 0a 09 09 | 09 09 09 7d 0a 09 09 09 |arg);...|...}....|
|00000f40| 09 09 65 6c 73 65 20 69 | 66 20 28 63 3d 3d 27 74 |..else i|f (c=='t|
|00000f50| 27 26 26 28 2a 76 29 5b | 32 5d 3d 3d 27 5c 30 27 |'&&(*v)[|2]=='\0'|
|00000f60| 29 7b 0a 09 09 09 09 09 | 09 2f 2a 20 74 68 69 73 |){......|./* this|
|00000f70| 20 69 73 20 61 6e 20 65 | 6d 70 74 79 20 74 61 67 | is an e|mpty tag|
|00000f80| 20 2d 20 69 67 6e 6f 72 | 65 20 69 74 20 2a 2f 0a | - ignor|e it */.|
|00000f90| 09 09 09 09 09 09 64 6f | 5f 76 69 28 2a 76 29 3b |......do|_vi(*v);|
|00000fa0| 0a 09 09 09 09 09 7d 0a | 09 09 09 09 09 65 6c 73 |......}.|.....els|
|00000fb0| 65 20 69 66 20 28 63 3d | 3d 27 72 27 26 26 28 2a |e if (c=|='r'&&(*|
|00000fc0| 76 29 5b 32 5d 3d 3d 27 | 5c 30 27 29 7b 0a 09 09 |v)[2]=='|\0'){...|
|00000fd0| 09 09 09 09 2f 2a 20 61 | 20 72 65 63 6f 76 65 72 |..../* a| recover|
|00000fe0| 2c 20 6a 75 73 74 20 70 | 61 73 73 20 69 74 20 74 |, just p|ass it t|
|00000ff0| 6f 20 76 69 20 61 6e 64 | 20 64 6f 6e 27 74 20 69 |o vi and| don't i|
|00001000| 6e 74 65 72 66 65 72 65 | 20 2a 2f 0a 09 09 09 09 |nterfere| */.....|
|00001010| 09 09 64 6f 5f 76 69 28 | 2a 76 29 3b 0a 09 09 09 |..do_vi(|*v);....|
|00001020| 09 09 7d 0a 09 09 09 09 | 09 65 6c 73 65 7b 0a 09 |..}.....|.else{..|
|00001030| 09 09 09 09 09 2f 2a 20 | 74 68 69 73 20 69 73 20 |...../* |this is |
|00001040| 61 20 70 61 74 74 65 72 | 6e 20 2d 20 74 72 79 20 |a patter|n - try |
|00001050| 74 6f 20 6d 61 74 63 68 | 20 69 74 20 2a 2f 0a 09 |to match| it */..|
|00001060| 09 09 09 09 09 66 69 6e | 64 5f 6d 61 74 63 68 28 |.....fin|d_match(|
|00001070| 2b 2b 2a 76 29 3b 0a 09 | 09 09 09 09 09 64 6f 5f |++*v);..|.....do_|
|00001080| 76 69 28 61 72 67 29 3b | 0a 09 09 09 09 09 7d 0a |vi(arg);|......}.|
|00001090| 09 09 09 09 09 62 72 65 | 61 6b 3b 0a 0a 09 09 09 |.....bre|ak;.....|
|000010a0| 09 63 61 73 65 20 27 2b | 27 3a 0a 09 09 09 09 09 |.case '+|':......|
|000010b0| 2f 2a 20 61 20 63 6f 6d | 6d 61 6e 64 2c 20 70 75 |/* a com|mand, pu|
|000010c0| 74 20 69 74 20 62 65 66 | 6f 72 65 20 74 68 65 20 |t it bef|ore the |
|000010d0| 6c 61 73 74 20 66 69 6c | 65 20 6e 61 6d 65 20 65 |last fil|e name e|
|000010e0| 74 63 20 2a 2f 0a 09 09 | 09 09 09 69 6e 73 65 72 |tc */...|...inser|
|000010f0| 74 5f 63 6f 6d 6d 61 6e | 64 28 2a 76 29 3b 0a 09 |t_comman|d(*v);..|
|00001100| 09 09 09 09 64 6f 5f 76 | 69 28 61 72 67 29 3b 0a |....do_v|i(arg);.|
|00001110| 09 09 09 09 09 62 72 65 | 61 6b 3b 0a 0a 09 09 09 |.....bre|ak;.....|
|00001120| 09 63 61 73 65 20 27 2e | 27 3a 0a 09 09 09 09 09 |.case '.|':......|
|00001130| 2f 2a 20 6a 75 73 74 20 | 67 69 76 65 20 61 20 68 |/* just |give a h|
|00001140| 69 73 74 6f 72 79 20 6c | 69 73 74 20 69 66 20 74 |istory l|ist if t|
|00001150| 68 65 72 65 20 69 73 20 | 6f 6e 6c 79 20 61 20 64 |here is |only a d|
|00001160| 6f 74 20 2a 2f 0a 09 09 | 09 09 09 69 66 20 28 28 |ot */...|...if ((|
|00001170| 2a 76 29 5b 31 5d 3d 3d | 27 5c 30 27 29 7b 0a 09 |*v)[1]==|'\0'){..|
|00001180| 09 09 09 09 09 72 65 67 | 69 73 74 65 72 20 63 74 |.....reg|ister ct|
|00001190| 3b 0a 09 09 09 09 09 09 | 72 65 67 69 73 74 65 72 |;.......|register|
|000011a0| 20 69 3b 0a 0a 09 09 09 | 09 09 09 72 65 61 64 5f | i;.....|...read_|
|000011b0| 68 69 73 74 28 64 6f 74 | 73 74 72 69 6e 67 29 3b |hist(dot|string);|
|000011c0| 0a 09 09 09 09 09 09 63 | 74 3d 73 70 6c 69 74 5f |.......c|t=split_|
|000011d0| 68 69 73 74 28 29 3b 0a | 0a 09 09 09 09 09 09 66 |hist();.|.......f|
|000011e0| 6f 72 20 28 69 3d 30 3b | 69 3c 63 74 3b 69 2b 2b |or (i=0;|i<ct;i++|
|000011f0| 29 7b 0a 09 09 09 09 09 | 09 09 66 70 72 69 6e 74 |){......|..fprint|
|00001200| 66 28 73 74 64 65 72 72 | 2c 22 5c 74 5b 25 64 5d |f(stderr|,"\t[%d]|
|00001210| 3a 20 25 73 5c 6e 22 2c | 63 74 2d 69 2d 31 2c 68 |: %s\n",|ct-i-1,h|
|00001220| 69 73 74 5b 63 74 2d 69 | 2d 31 5d 29 3b 0a 09 09 |ist[ct-i|-1]);...|
|00001230| 09 09 09 09 7d 0a 09 09 | 09 09 09 09 65 78 69 74 |....}...|....exit|
|00001240| 28 30 29 3b 0a 09 09 09 | 09 09 7d 0a 09 09 09 09 |(0);....|..}.....|
|00001250| 09 2f 2a 20 0a 09 09 09 | 09 09 20 20 20 57 41 52 |./* ....|.. WAR|
|00001260| 4e 49 4e 47 21 0a 09 09 | 09 09 09 20 20 20 74 68 |NING!...|... th|
|00001270| 65 20 73 77 69 74 63 68 | 20 66 61 6c 6c 73 20 74 |e switch| falls t|
|00001280| 68 72 6f 75 67 68 20 69 | 6e 20 74 68 65 20 63 61 |hrough i|n the ca|
|00001290| 73 65 20 77 68 65 72 65 | 20 74 68 65 72 65 20 69 |se where| there i|
|000012a0| 73 20 61 0a 09 09 09 09 | 09 20 20 20 70 61 74 74 |s a.....|. patt|
|000012b0| 65 72 6e 20 74 68 61 74 | 20 73 74 61 72 74 73 20 |ern that| starts |
|000012c0| 77 69 74 68 20 61 20 70 | 65 72 69 6f 64 0a 09 09 |with a p|eriod...|
|000012d0| 09 09 09 2a 2f 0a 0a 09 | 09 09 09 64 65 66 61 75 |...*/...|...defau|
|000012e0| 6c 74 20 3a 0a 09 09 09 | 09 09 2f 2a 20 6c 6f 6f |lt :....|../* loo|
|000012f0| 6b 73 20 6c 69 6b 65 20 | 69 74 27 73 20 6a 75 73 |ks like |it's jus|
|00001300| 74 20 61 20 70 6c 61 69 | 6e 20 6f 6c 64 20 66 69 |t a plai|n old fi|
|00001310| 6c 65 20 6e 61 6d 65 2e | 20 76 69 20 69 74 21 20 |le name.| vi it! |
|00001320| 2a 2f 0a 09 09 09 09 09 | 6e 6f 72 6d 61 6c 28 2a |*/......|normal(*|
|00001330| 76 29 3b 0a 09 09 09 09 | 09 64 6f 5f 76 69 28 61 |v);.....|.do_vi(a|
|00001340| 72 67 29 3b 0a 09 09 09 | 09 09 62 72 65 61 6b 3b |rg);....|..break;|
|00001350| 0a 09 09 09 7d 0a 09 09 | 64 65 66 61 75 6c 74 3a |....}...|default:|
|00001360| 0a 09 09 09 2f 2a 20 61 | 20 62 75 6e 63 68 20 6f |..../* a| bunch o|
|00001370| 66 20 61 72 67 75 6d 65 | 6e 74 73 2c 20 66 69 78 |f argume|nts, fix|
|00001380| 20 74 68 65 20 68 69 73 | 74 6f 72 79 20 26 20 76 | the his|tory & v|
|00001390| 69 20 74 68 65 6d 20 61 | 6c 6c 20 61 73 20 6e 6f |i them a|ll as no|
|000013a0| 72 6d 61 6c 20 2a 2f 0a | 09 09 09 6d 75 6c 74 69 |rmal */.|...multi|
|000013b0| 70 6c 65 28 63 2c 76 29 | 3b 0a 09 09 09 64 6f 5f |ple(c,v)|;....do_|
|000013c0| 76 69 28 61 72 67 29 3b | 0a 09 09 09 62 72 65 61 |vi(arg);|....brea|
|000013d0| 6b 3b 0a 09 7d 0a 7d 0a | 0a 0a 0a 72 65 61 64 5f |k;..}.}.|...read_|
|000013e0| 68 69 73 74 28 64 69 72 | 6e 61 6d 65 29 0a 63 68 |hist(dir|name).ch|
|000013f0| 61 72 20 2a 64 69 72 6e | 61 6d 65 3b 0a 7b 0a 09 |ar *dirn|ame;.{..|
|00001400| 2f 2a 0a 09 20 20 20 72 | 65 61 64 20 74 68 65 20 |/*.. r|ead the |
|00001410| 68 69 73 74 6f 72 79 20 | 66 69 6c 65 20 61 6e 64 |history |file and|
|00001420| 20 62 72 65 61 6b 20 69 | 74 20 75 70 20 69 6e 74 | break i|t up int|
|00001430| 6f 20 6c 69 6e 65 73 20 | 69 6e 20 74 68 65 20 67 |o lines |in the g|
|00001440| 6c 6f 62 61 6c 20 76 61 | 72 69 61 62 6c 65 0a 09 |lobal va|riable..|
|00001450| 20 20 20 27 68 69 73 74 | 6f 72 79 27 2e 20 64 6f | 'hist|ory'. do|
|00001460| 20 74 68 65 20 61 70 70 | 72 6f 70 72 69 61 74 65 | the app|ropriate|
|00001470| 20 63 68 65 63 6b 73 20 | 74 6f 20 73 65 65 20 74 | checks |to see t|
|00001480| 68 61 74 20 69 74 20 65 | 78 69 73 74 73 20 65 74 |hat it e|xists et|
|00001490| 63 2e 2e 2e 0a 09 2a 2f | 0a 0a 09 72 65 67 69 73 |c.....*/|...regis|
|000014a0| 74 65 72 20 76 68 3b 0a | 09 72 65 67 69 73 74 65 |ter vh;.|.registe|
|000014b0| 72 20 62 79 74 65 73 3b | 0a 09 72 65 67 69 73 74 |r bytes;|..regist|
|000014c0| 65 72 20 6f 66 66 73 65 | 74 3b 0a 09 73 74 72 75 |er offse|t;..stru|
|000014d0| 63 74 20 73 74 61 74 20 | 62 75 66 3b 0a 09 63 68 |ct stat |buf;..ch|
|000014e0| 61 72 20 64 69 72 62 75 | 66 66 65 72 5b 48 46 49 |ar dirbu|ffer[HFI|
|000014f0| 4c 45 4c 45 4e 5d 3b 0a | 0a 0a 09 2f 2a 20 0a 09 |LELEN];.|.../* ..|
|00001500| 20 20 20 69 66 20 74 68 | 65 72 65 20 69 73 20 6e | if th|ere is n|
|00001510| 6f 20 68 69 73 74 6f 72 | 79 20 66 69 6c 65 20 74 |o histor|y file t|
|00001520| 68 65 6e 20 73 61 79 20 | 73 6f 20 61 6e 64 20 67 |hen say |so and g|
|00001530| 65 74 20 6f 75 74 20 6f | 66 20 68 65 72 65 20 2d |et out o|f here -|
|00001540| 20 74 68 65 79 20 0a 09 | 20 20 20 68 61 64 20 6e | they ..| had n|
|00001550| 6f 62 75 73 69 6e 65 73 | 73 20 61 73 6b 69 6e 67 |obusines|s asking|
|00001560| 20 66 6f 72 20 61 63 63 | 65 73 73 20 74 6f 20 74 | for acc|ess to t|
|00001570| 68 65 20 68 69 73 74 6f | 72 79 0a 09 2a 2f 0a 09 |he histo|ry..*/..|
|00001580| 73 70 72 69 6e 74 66 28 | 64 69 72 62 75 66 66 65 |sprintf(|dirbuffe|
|00001590| 72 2c 22 25 73 2f 25 73 | 22 2c 20 64 69 72 6e 61 |r,"%s/%s|", dirna|
|000015a0| 6d 65 2c 20 48 49 53 54 | 29 3b 0a 09 69 66 20 28 |me, HIST|);..if (|
|000015b0| 28 76 68 3d 6f 70 65 6e | 28 64 69 72 62 75 66 66 |(vh=open|(dirbuff|
|000015c0| 65 72 2c 4f 5f 52 44 4f | 4e 4c 59 29 29 3d 3d 2d |er,O_RDO|NLY))==-|
|000015d0| 31 29 7b 0a 09 09 70 65 | 72 72 6f 72 28 64 69 72 |1){...pe|rror(dir|
|000015e0| 62 75 66 66 65 72 29 3b | 0a 09 09 65 78 69 74 28 |buffer);|...exit(|
|000015f0| 31 29 3b 0a 09 7d 0a 0a | 09 2f 2a 20 73 74 61 74 |1);..}..|./* stat|
|00001600| 20 69 74 20 2a 2f 0a 09 | 69 66 20 28 66 73 74 61 | it */..|if (fsta|
|00001610| 74 28 76 68 2c 26 62 75 | 66 29 3d 3d 2d 31 29 7b |t(vh,&bu|f)==-1){|
|00001620| 0a 09 09 70 65 72 72 6f | 72 28 64 69 72 62 75 66 |...perro|r(dirbuf|
|00001630| 66 65 72 29 3b 0a 09 09 | 65 78 69 74 28 31 29 3b |fer);...|exit(1);|
|00001640| 0a 09 7d 0a 0a 09 2f 2a | 20 0a 09 20 20 20 73 65 |..}.../*| .. se|
|00001650| 74 20 27 6f 66 66 73 65 | 74 27 20 73 6f 20 74 68 |t 'offse|t' so th|
|00001660| 61 74 20 77 65 20 63 61 | 6e 20 72 65 61 64 20 74 |at we ca|n read t|
|00001670| 68 65 20 6c 61 73 74 20 | 70 6f 72 74 69 6f 6e 20 |he last |portion |
|00001680| 6f 66 20 74 68 65 20 68 | 69 73 74 6f 72 79 0a 09 |of the h|istory..|
|00001690| 20 20 20 66 69 6c 65 20 | 6f 6e 6c 79 2e 20 69 66 | file |only. if|
|000016a0| 20 74 68 65 72 65 20 61 | 72 65 20 6c 65 73 73 20 | there a|re less |
|000016b0| 74 68 61 6e 20 48 49 53 | 54 5f 43 48 41 52 53 20 |than HIS|T_CHARS |
|000016c0| 63 68 61 72 61 63 74 65 | 72 73 20 69 6e 20 74 68 |characte|rs in th|
|000016d0| 65 0a 09 20 20 20 66 69 | 6c 65 20 74 68 65 6e 20 |e.. fi|le then |
|000016e0| 77 65 20 77 69 6c 6c 20 | 73 74 61 72 74 20 72 65 |we will |start re|
|000016f0| 61 64 69 6e 67 20 61 74 | 20 30 2c 20 6f 74 68 65 |ading at| 0, othe|
|00001700| 72 77 69 73 65 20 61 74 | 20 48 49 53 54 5f 43 48 |rwise at| HIST_CH|
|00001710| 41 52 53 0a 09 20 20 20 | 63 68 61 72 61 63 74 65 |ARS.. |characte|
|00001720| 72 73 20 62 65 66 6f 72 | 65 20 74 68 65 20 65 6e |rs befor|e the en|
|00001730| 64 20 6f 66 20 74 68 65 | 20 66 69 6c 65 2e 0a 09 |d of the| file...|
|00001740| 2a 2f 0a 09 6f 66 66 73 | 65 74 3d 28 69 6e 74 29 |*/..offs|et=(int)|
|00001750| 62 75 66 2e 73 74 5f 73 | 69 7a 65 2d 48 49 53 54 |buf.st_s|ize-HIST|
|00001760| 5f 43 48 41 52 53 3c 30 | 20 3f 20 30 20 3a 20 62 |_CHARS<0| ? 0 : b|
|00001770| 75 66 2e 73 74 5f 73 69 | 7a 65 2d 48 49 53 54 5f |uf.st_si|ze-HIST_|
|00001780| 43 48 41 52 53 3b 0a 0a | 09 2f 2a 20 6d 6f 76 65 |CHARS;..|./* move|
|00001790| 20 74 6f 20 74 68 61 74 | 20 70 6c 61 63 65 20 69 | to that| place i|
|000017a0| 6e 20 74 68 65 20 66 69 | 6c 65 20 2a 2f 0a 09 69 |n the fi|le */..i|
|000017b0| 66 20 28 6c 73 65 65 6b | 28 76 68 2c 28 6c 6f 6e |f (lseek|(vh,(lon|
|000017c0| 67 29 6f 66 66 73 65 74 | 2c 4c 5f 53 45 54 29 3d |g)offset|,L_SET)=|
|000017d0| 3d 2d 31 29 7b 0a 09 09 | 70 65 72 72 6f 72 28 64 |=-1){...|perror(d|
|000017e0| 69 72 62 75 66 66 65 72 | 29 3b 0a 09 09 65 78 69 |irbuffer|);...exi|
|000017f0| 74 28 31 29 3b 0a 09 7d | 0a 0a 09 2f 2a 20 61 6e |t(1);..}|.../* an|
|00001800| 64 20 52 45 41 44 21 20 | 2a 2f 0a 09 69 66 20 28 |d READ! |*/..if (|
|00001810| 28 62 79 74 65 73 3d 72 | 65 61 64 28 76 68 2c 68 |(bytes=r|ead(vh,h|
|00001820| 69 73 74 6f 72 79 2c 48 | 49 53 54 5f 43 48 41 52 |istory,H|IST_CHAR|
|00001830| 53 29 29 3d 3d 2d 31 29 | 7b 0a 09 09 70 65 72 72 |S))==-1)|{...perr|
|00001840| 6f 72 28 64 69 72 62 75 | 66 66 65 72 29 3b 0a 09 |or(dirbu|ffer);..|
|00001850| 09 65 78 69 74 28 31 29 | 3b 0a 09 7d 0a 0a 09 2f |.exit(1)|;..}.../|
|00001860| 2a 20 69 66 20 77 65 20 | 64 69 64 6e 27 74 20 63 |* if we |didn't c|
|00001870| 6f 6d 65 20 75 70 20 77 | 69 74 68 20 41 4e 59 54 |ome up w|ith ANYT|
|00001880| 48 49 4e 47 20 77 65 20 | 6d 61 79 20 61 73 20 77 |HING we |may as w|
|00001890| 65 6c 6c 20 6c 65 61 76 | 65 20 2a 2f 0a 09 69 66 |ell leav|e */..if|
|000018a0| 20 28 21 62 79 74 65 73 | 29 7b 0a 09 09 66 70 72 | (!bytes|){...fpr|
|000018b0| 69 6e 74 66 28 73 74 64 | 65 72 72 2c 22 45 6d 70 |intf(std|err,"Emp|
|000018c0| 74 79 20 25 73 20 66 69 | 6c 65 2e 5c 6e 22 2c 64 |ty %s fi|le.\n",d|
|000018d0| 69 72 62 75 66 66 65 72 | 29 3b 0a 09 09 65 78 69 |irbuffer|);...exi|
|000018e0| 74 28 31 29 3b 0a 09 7d | 0a 0a 09 2f 2a 20 7a 61 |t(1);..}|.../* za|
|000018f0| 70 20 74 68 65 20 6e 65 | 77 6c 69 6e 65 20 28 77 |p the ne|wline (w|
|00001900| 68 69 63 68 20 73 68 6f | 75 6c 64 20 62 65 20 74 |hich sho|uld be t|
|00001910| 68 65 72 65 29 20 66 6f | 72 20 6e 6f 77 20 2a 2f |here) fo|r now */|
|00001920| 0a 09 69 66 20 28 68 69 | 73 74 6f 72 79 5b 2d 2d |..if (hi|story[--|
|00001930| 62 79 74 65 73 5d 3d 3d | 27 5c 6e 27 29 7b 0a 09 |bytes]==|'\n'){..|
|00001940| 09 68 69 73 74 6f 72 79 | 5b 62 79 74 65 73 5d 3d |.history|[bytes]=|
|00001950| 27 5c 30 27 3b 09 0a 09 | 7d 0a 0a 09 2f 2a 20 61 |'\0';...|}.../* a|
|00001960| 6e 64 20 67 65 74 20 6f | 75 74 20 6f 66 20 68 65 |nd get o|ut of he|
|00001970| 72 65 20 2a 2f 0a 09 72 | 65 74 75 72 6e 28 62 79 |re */..r|eturn(by|
|00001980| 74 65 73 29 3b 0a 7d 0a | 0a 6c 61 73 74 5f 66 69 |tes);.}.|.last_fi|
|00001990| 6c 65 28 29 0a 7b 0a 09 | 2f 2a 0a 09 20 20 20 67 |le().{..|/*.. g|
|000019a0| 65 74 20 74 68 65 20 6c | 61 73 74 20 6e 61 6d 65 |et the l|ast name|
|000019b0| 20 66 72 6f 6d 20 74 68 | 65 20 27 68 69 73 74 6f | from th|e 'histo|
|000019c0| 72 79 27 20 61 72 72 61 | 79 20 61 6e 64 20 70 75 |ry' arra|y and pu|
|000019d0| 74 20 69 74 20 69 6e 74 | 6f 20 27 61 72 67 27 0a |t it int|o 'arg'.|
|000019e0| 09 2a 2f 0a 0a 09 72 65 | 61 64 5f 68 69 73 74 28 |.*/...re|ad_hist(|
|000019f0| 64 6f 74 73 74 72 69 6e | 67 29 3b 0a 09 69 66 20 |dotstrin|g);..if |
|00001a00| 28 69 6e 64 65 78 28 68 | 69 73 74 6f 72 79 2c 27 |(index(h|istory,'|
|00001a10| 5c 6e 27 29 3d 3d 4e 55 | 4c 4c 29 7b 0a 09 09 69 |\n')==NU|LL){...i|
|00001a20| 66 20 28 2a 68 69 73 74 | 6f 72 79 3d 3d 27 5c 30 |f (*hist|ory=='\0|
|00001a30| 27 29 7b 0a 09 09 09 66 | 70 72 69 6e 74 66 28 73 |'){....f|printf(s|
|00001a40| 74 64 65 72 72 2c 22 25 | 73 3a 20 62 61 64 6c 79 |tderr,"%|s: badly|
|00001a50| 20 66 6f 72 6d 61 74 74 | 65 64 2e 5c 6e 22 2c 48 | formatt|ed.\n",H|
|00001a60| 49 53 54 29 3b 0a 09 09 | 09 65 78 69 74 28 31 29 |IST);...|.exit(1)|
|00001a70| 3b 0a 09 09 7d 0a 09 09 | 65 6c 73 65 7b 0a 09 09 |;...}...|else{...|
|00001a80| 09 73 70 72 69 6e 74 66 | 28 61 72 67 2c 22 25 73 |.sprintf|(arg,"%s|
|00001a90| 22 2c 68 69 73 74 6f 72 | 79 29 3b 0a 09 09 7d 0a |",histor|y);...}.|
|00001aa0| 09 7d 0a 09 65 6c 73 65 | 7b 0a 09 09 73 70 72 69 |.}..else|{...spri|
|00001ab0| 6e 74 66 28 61 72 67 2c | 22 25 73 22 2c 72 69 6e |ntf(arg,|"%s",rin|
|00001ac0| 64 65 78 28 68 69 73 74 | 6f 72 79 2c 27 5c 6e 27 |dex(hist|ory,'\n'|
|00001ad0| 29 2b 31 29 3b 0a 09 7d | 0a 7d 0a 0a 73 70 6c 69 |)+1);..}|.}..spli|
|00001ae0| 74 5f 68 69 73 74 28 29 | 0a 7b 0a 09 2f 2a 0a 09 |t_hist()|.{../*..|
|00001af0| 20 20 20 73 65 74 20 74 | 68 65 20 61 72 72 61 79 | set t|he array|
|00001b00| 20 6f 66 20 70 6f 69 6e | 74 65 72 73 20 69 6e 20 | of poin|ters in |
|00001b10| 27 68 69 73 74 27 20 74 | 6f 20 70 6f 69 6e 74 20 |'hist' t|o point |
|00001b20| 74 6f 20 74 68 65 20 73 | 75 63 63 65 73 69 76 65 |to the s|uccesive|
|00001b30| 20 6e 61 6d 65 73 0a 09 | 20 20 20 69 6e 20 74 68 | names..| in th|
|00001b40| 65 20 27 68 69 73 74 6f | 72 79 27 20 61 72 72 61 |e 'histo|ry' arra|
|00001b50| 79 2e 20 74 68 65 73 65 | 20 61 72 65 20 64 65 6c |y. these| are del|
|00001b60| 69 6d 69 74 65 64 20 28 | 70 72 65 73 75 6d 61 62 |imited (|presumab|
|00001b70| 6c 79 29 20 62 79 20 6e | 65 77 6c 69 6e 65 73 0a |ly) by n|ewlines.|
|00001b80| 09 20 20 20 61 6e 64 20 | 73 6f 20 74 68 65 79 27 |. and |so they'|
|00001b90| 72 65 20 65 61 73 79 20 | 74 6f 20 63 61 74 63 68 |re easy |to catch|
|00001ba0| 2e 2e 2e 0a 0a 09 20 20 | 20 77 68 61 74 20 69 6e |...... | what in|
|00001bb0| 20 66 61 63 74 20 69 73 | 20 64 6f 6e 65 20 69 73 | fact is| done is|
|00001bc0| 20 74 68 61 74 20 74 68 | 65 20 68 69 73 74 6f 72 | that th|e histor|
|00001bd0| 79 20 61 72 72 61 79 20 | 69 73 20 63 6f 70 69 65 |y array |is copie|
|00001be0| 64 20 61 6e 64 20 77 65 | 20 73 65 74 0a 09 20 20 |d and we| set.. |
|00001bf0| 20 74 68 65 20 70 6f 69 | 6e 74 65 72 73 20 75 70 | the poi|nters up|
|00001c00| 20 61 6e 64 20 73 65 74 | 20 74 68 65 20 6e 65 77 | and set| the new|
|00001c10| 6c 69 6e 65 73 20 74 6f | 20 62 65 20 27 5c 30 27 |lines to| be '\0'|
|00001c20| 20 73 2e 20 74 68 69 73 | 20 77 61 79 20 77 65 20 | s. this| way we |
|00001c30| 64 6f 6e 27 74 0a 09 20 | 20 20 6d 65 73 73 20 75 |don't.. | mess u|
|00001c40| 70 20 74 68 65 20 68 69 | 73 74 6f 72 79 20 61 72 |p the hi|story ar|
|00001c50| 72 61 79 20 61 73 20 77 | 65 20 77 69 6c 6c 20 77 |ray as w|e will w|
|00001c60| 61 6e 74 20 69 74 20 69 | 6e 74 61 63 74 20 6c 61 |ant it i|ntact la|
|00001c70| 74 65 72 20 6f 6e 20 28 | 6d 61 79 62 65 29 2e 0a |ter on (|maybe)..|
|00001c80| 09 2a 2f 0a 0a 09 63 68 | 61 72 20 2a 74 6d 70 3b |.*/...ch|ar *tmp;|
|00001c90| 0a 09 72 65 67 69 73 74 | 65 72 20 63 6f 75 6e 74 |..regist|er count|
|00001ca0| 3b 0a 0a 09 2f 2a 20 63 | 6f 70 79 20 69 74 20 2a |;.../* c|opy it *|
|00001cb0| 2f 0a 09 73 70 72 69 6e | 74 66 28 74 65 6d 70 2c |/..sprin|tf(temp,|
|00001cc0| 22 25 73 22 2c 68 69 73 | 74 6f 72 79 29 3b 0a 0a |"%s",his|tory);..|
|00001cd0| 09 2f 2a 20 0a 09 20 20 | 20 6e 6f 77 20 72 75 6e |./* .. | now run|
|00001ce0| 20 74 68 72 6f 75 67 68 | 20 62 72 65 61 6b 69 6e | through| breakin|
|00001cf0| 67 20 69 74 20 75 70 2c | 20 73 65 74 74 69 6e 67 |g it up,| setting|
|00001d00| 20 70 6f 69 6e 74 65 72 | 73 20 61 6e 64 20 72 65 | pointer|s and re|
|00001d10| 74 75 72 6e 20 74 68 65 | 20 6e 75 6d 62 65 72 20 |turn the| number |
|00001d20| 0a 09 20 20 20 6f 66 20 | 6c 69 6e 65 73 20 77 65 |.. of |lines we|
|00001d30| 20 66 6f 75 6e 64 2e 0a | 09 2a 2f 0a 09 66 6f 72 | found..|.*/..for|
|00001d40| 20 28 63 6f 75 6e 74 3d | 30 3b 63 6f 75 6e 74 3c | (count=|0;count<|
|00001d50| 48 49 53 54 5f 4c 49 4e | 45 53 3b 63 6f 75 6e 74 |HIST_LIN|ES;count|
|00001d60| 2b 2b 29 7b 0a 09 09 69 | 66 20 28 28 74 6d 70 3d |++){...i|f ((tmp=|
|00001d70| 68 69 73 74 5b 63 6f 75 | 6e 74 5d 3d 72 69 6e 64 |hist[cou|nt]=rind|
|00001d80| 65 78 28 74 65 6d 70 2c | 27 5c 6e 27 29 29 3d 3d |ex(temp,|'\n'))==|
|00001d90| 4e 55 4c 4c 29 7b 0a 09 | 09 09 62 72 65 61 6b 3b |NULL){..|..break;|
|00001da0| 0a 09 09 7d 0a 09 09 2a | 74 6d 70 3d 27 5c 30 27 |...}...*|tmp='\0'|
|00001db0| 3b 0a 09 09 68 69 73 74 | 5b 63 6f 75 6e 74 5d 2b |;...hist|[count]+|
|00001dc0| 2b 3b 0a 09 7d 0a 09 69 | 66 20 28 63 6f 75 6e 74 |+;..}..i|f (count|
|00001dd0| 3c 48 49 53 54 5f 4c 49 | 4e 45 53 29 7b 0a 09 09 |<HIST_LI|NES){...|
|00001de0| 68 69 73 74 5b 63 6f 75 | 6e 74 2b 2b 5d 3d 74 65 |hist[cou|nt++]=te|
|00001df0| 6d 70 3b 0a 09 7d 0a 09 | 72 65 74 75 72 6e 28 63 |mp;..}..|return(c|
|00001e00| 6f 75 6e 74 29 3b 0a 7d | 0a 0a 6e 74 68 5f 68 69 |ount);.}|..nth_hi|
|00001e10| 73 74 28 6e 29 0a 69 6e | 74 20 6e 3b 0a 7b 0a 09 |st(n).in|t n;.{..|
|00001e20| 2f 2a 0a 09 20 20 20 67 | 65 74 20 74 68 65 20 6e |/*.. g|et the n|
|00001e30| 74 68 20 6c 61 73 74 20 | 66 69 6c 65 6e 61 6d 65 |th last |filename|
|00001e40| 20 66 72 6f 6d 20 74 68 | 65 20 6c 69 73 74 2e 20 | from th|e list. |
|00001e50| 6d 61 6b 65 20 75 73 65 | 20 28 6f 66 20 63 6f 75 |make use| (of cou|
|00001e60| 72 73 65 29 20 6f 66 0a | 09 20 20 20 72 65 61 64 |rse) of.|. read|
|00001e70| 5f 68 69 73 74 20 61 6e | 64 20 73 70 6c 69 74 5f |_hist an|d split_|
|00001e80| 68 69 73 74 2e 0a 09 2a | 2f 0a 09 72 65 67 69 73 |hist...*|/..regis|
|00001e90| 74 65 72 20 63 6f 75 6e | 74 3b 0a 09 72 65 67 69 |ter coun|t;..regi|
|00001ea0| 73 74 65 72 20 69 3b 0a | 0a 09 72 65 61 64 5f 68 |ster i;.|..read_h|
|00001eb0| 69 73 74 28 64 6f 74 73 | 74 72 69 6e 67 29 3b 0a |ist(dots|tring);.|
|00001ec0| 09 63 6f 75 6e 74 3d 73 | 70 6c 69 74 5f 68 69 73 |.count=s|plit_his|
|00001ed0| 74 28 29 3b 0a 09 69 66 | 20 28 6e 3e 63 6f 75 6e |t();..if| (n>coun|
|00001ee0| 74 2d 31 29 7b 0a 09 09 | 69 66 20 28 63 6f 75 6e |t-1){...|if (coun|
|00001ef0| 74 3e 31 29 7b 0a 09 09 | 09 66 70 72 69 6e 74 66 |t>1){...|.fprintf|
|00001f00| 28 73 74 64 65 72 72 2c | 22 4f 6e 6c 79 20 25 64 |(stderr,|"Only %d|
|00001f10| 20 68 69 73 74 6f 72 79 | 20 69 74 65 6d 73 20 65 | history| items e|
|00001f20| 78 69 73 74 2e 5c 6e 22 | 2c 63 6f 75 6e 74 29 3b |xist.\n"|,count);|
|00001f30| 0a 09 09 7d 0a 09 09 65 | 6c 73 65 7b 0a 09 09 09 |...}...e|lse{....|
|00001f40| 66 70 72 69 6e 74 66 28 | 73 74 64 65 72 72 2c 22 |fprintf(|stderr,"|
|00001f50| 4f 6e 6c 79 20 6f 6e 65 | 20 68 69 73 74 6f 72 79 |Only one| history|
|00001f60| 20 69 74 65 6d 20 65 78 | 69 73 74 73 2e 5c 6e 22 | item ex|ists.\n"|
|00001f70| 29 3b 0a 09 09 7d 0a 09 | 09 65 78 69 74 28 31 29 |);...}..|.exit(1)|
|00001f80| 3b 0a 09 7d 0a 09 73 70 | 72 69 6e 74 66 28 61 72 |;..}..sp|rintf(ar|
|00001f90| 67 2c 22 25 73 22 2c 68 | 69 73 74 5b 6e 5d 29 3b |g,"%s",h|ist[n]);|
|00001fa0| 0a 0a 09 2f 2a 20 72 65 | 62 75 69 6c 64 20 74 68 |.../* re|build th|
|00001fb0| 65 20 68 69 73 74 6f 72 | 79 20 77 69 74 68 20 74 |e histor|y with t|
|00001fc0| 68 65 20 73 65 6c 65 63 | 74 65 64 20 6e 61 6d 65 |he selec|ted name|
|00001fd0| 20 61 74 20 74 68 65 20 | 62 6f 74 74 6f 6d 20 2a | at the |bottom *|
|00001fe0| 2f 0a 09 72 65 63 6f 6e | 73 74 72 75 63 74 28 6e |/..recon|struct(n|
|00001ff0| 2c 63 6f 75 6e 74 2c 64 | 6f 74 73 74 72 69 6e 67 |,count,d|otstring|
|00002000| 29 3b 0a 7d 0a 0a 61 73 | 6b 5f 68 69 73 74 28 29 |);.}..as|k_hist()|
|00002010| 0a 7b 0a 09 2f 2a 0a 09 | 20 20 20 61 73 6b 20 74 |.{../*..| ask t|
|00002020| 68 65 20 6f 75 74 73 69 | 64 65 20 77 6f 72 6c 64 |he outsi|de world|
|00002030| 20 77 68 69 63 68 20 6f | 66 20 74 68 65 20 66 69 | which o|f the fi|
|00002040| 6c 65 73 20 69 6e 20 74 | 68 65 20 68 69 73 74 6f |les in t|he histo|
|00002050| 72 79 20 69 73 20 77 61 | 6e 74 65 64 2e 0a 09 20 |ry is wa|nted... |
|00002060| 20 20 73 65 74 20 74 68 | 65 20 74 65 72 6d 69 6e | set th|e termin|
|00002070| 61 6c 20 74 6f 20 63 62 | 72 65 61 6b 2e 0a 09 2a |al to cb|reak...*|
|00002080| 2f 0a 09 72 65 67 69 73 | 74 65 72 20 69 3b 0a 09 |/..regis|ter i;..|
|00002090| 72 65 67 69 73 74 65 72 | 20 63 6f 75 6e 74 3b 0a |register| count;.|
|000020a0| 09 63 68 61 72 20 2a 6c | 61 73 74 3b 0a 09 72 65 |.char *l|ast;..re|
|000020b0| 67 69 73 74 65 72 20 6f | 70 74 69 6f 6e 3b 0a 0a |gister o|ption;..|
|000020c0| 09 2f 2a 20 72 65 61 64 | 20 61 6e 64 20 73 70 6c |./* read| and spl|
|000020d0| 69 74 20 74 68 65 20 68 | 69 73 74 6f 72 79 20 66 |it the h|istory f|
|000020e0| 69 6c 65 20 2a 2f 0a 09 | 72 65 61 64 5f 68 69 73 |ile */..|read_his|
|000020f0| 74 28 64 6f 74 73 74 72 | 69 6e 67 29 3b 0a 09 63 |t(dotstr|ing);..c|
|00002100| 6f 75 6e 74 3d 73 70 6c | 69 74 5f 68 69 73 74 28 |ount=spl|it_hist(|
|00002110| 29 3b 0a 0a 09 2f 2a 20 | 70 72 69 6e 74 20 74 68 |);.../* |print th|
|00002120| 65 20 68 69 73 74 6f 72 | 79 20 2a 2f 0a 09 66 6f |e histor|y */..fo|
|00002130| 72 20 28 69 3d 30 3b 69 | 3c 63 6f 75 6e 74 3b 69 |r (i=0;i|<count;i|
|00002140| 2b 2b 29 7b 0a 09 09 66 | 70 72 69 6e 74 66 28 73 |++){...f|printf(s|
|00002150| 74 64 65 72 72 2c 22 5c | 74 5b 25 64 5d 3a 20 25 |tderr,"\|t[%d]: %|
|00002160| 73 5c 6e 22 2c 63 6f 75 | 6e 74 2d 28 69 2b 31 29 |s\n",cou|nt-(i+1)|
|00002170| 2c 68 69 73 74 5b 63 6f | 75 6e 74 2d 69 2d 31 5d |,hist[co|unt-i-1]|
|00002180| 29 3b 0a 09 7d 0a 0a 09 | 2f 2a 20 67 69 76 65 20 |);..}...|/* give |
|00002190| 74 68 65 6d 20 61 20 70 | 72 6f 6d 70 74 20 28 6f |them a p|rompt (o|
|000021a0| 66 20 73 6f 72 74 73 29 | 20 2a 2f 0a 09 66 70 72 |f sorts)| */..fpr|
|000021b0| 69 6e 74 66 28 73 74 64 | 65 72 72 2c 22 73 65 6c |intf(std|err,"sel|
|000021c0| 65 63 74 20 2d 3e 20 22 | 29 3b 0a 0a 09 2f 2a 20 |ect -> "|);.../* |
|000021d0| 73 65 74 20 74 68 65 20 | 74 65 72 6d 69 6e 61 6c |set the |terminal|
|000021e0| 20 75 70 20 2a 2f 0a 09 | 73 65 74 5f 74 65 72 6d | up */..|set_term|
|000021f0| 28 29 3b 0a 0a 09 2f 2a | 20 67 65 74 20 74 68 65 |();.../*| get the|
|00002200| 69 72 20 72 65 73 70 6f | 6e 73 65 20 2a 2f 0a 09 |ir respo|nse */..|
|00002210| 6f 70 74 69 6f 6e 3d 67 | 65 74 63 28 73 74 64 69 |option=g|etc(stdi|
|00002220| 6e 29 3b 0a 0a 09 2f 2a | 20 6d 61 6b 65 20 74 68 |n);.../*| make th|
|00002230| 65 20 74 65 72 6d 69 6e | 61 6c 20 27 73 61 66 65 |e termin|al 'safe|
|00002240| 27 20 61 67 61 69 6e 20 | 2a 2f 0a 09 75 6e 73 65 |' again |*/..unse|
|00002250| 74 5f 74 65 72 6d 28 29 | 3b 0a 0a 09 2f 2a 20 0a |t_term()|;.../* .|
|00002260| 09 20 20 20 70 72 6f 63 | 65 73 73 20 74 68 65 20 |. proc|ess the |
|00002270| 6f 70 74 69 6f 6e 20 61 | 6e 64 20 70 75 74 20 74 |option a|nd put t|
|00002280| 68 65 20 61 70 70 72 6f | 70 72 69 61 74 65 20 66 |he appro|priate f|
|00002290| 69 6c 65 20 6e 61 6d 65 | 20 69 6e 74 6f 20 74 68 |ile name| into th|
|000022a0| 65 20 0a 09 20 20 20 61 | 72 67 20 76 61 72 69 61 |e .. a|rg varia|
|000022b0| 62 6c 65 2e 0a 09 2a 2f | 0a 09 69 66 20 28 6f 70 |ble...*/|..if (op|
|000022c0| 74 69 6f 6e 3d 3d 27 5c | 6e 27 29 7b 0a 09 09 2f |tion=='\|n'){.../|
|000022d0| 2a 20 74 68 65 79 20 77 | 61 6e 74 20 74 68 65 20 |* they w|ant the |
|000022e0| 6c 61 73 74 20 66 69 6c | 65 20 6f 66 20 74 68 65 |last fil|e of the|
|000022f0| 20 6c 69 73 74 20 2a 2f | 0a 09 09 66 70 72 69 6e | list */|...fprin|
|00002300| 74 66 28 73 74 64 65 72 | 72 2c 22 25 73 5c 6e 22 |tf(stder|r,"%s\n"|
|00002310| 2c 68 69 73 74 5b 30 5d | 29 3b 0a 09 09 73 70 72 |,hist[0]|);...spr|
|00002320| 69 6e 74 66 28 61 72 67 | 2c 22 25 73 22 2c 68 69 |intf(arg|,"%s",hi|
|00002330| 73 74 5b 30 5d 29 3b 0a | 09 09 72 65 74 75 72 6e |st[0]);.|..return|
|00002340| 3b 0a 09 7d 0a 09 65 6c | 73 65 20 69 66 20 28 6f |;..}..el|se if (o|
|00002350| 70 74 69 6f 6e 3d 3d 72 | 75 62 6f 75 74 29 7b 0a |ption==r|ubout){.|
|00002360| 09 09 2f 2a 20 74 68 65 | 79 20 77 61 6e 74 20 74 |../* the|y want t|
|00002370| 6f 20 6c 65 61 76 65 20 | 2a 2f 0a 09 09 66 70 72 |o leave |*/...fpr|
|00002380| 69 6e 74 66 28 73 74 64 | 65 72 72 2c 22 5c 6e 22 |intf(std|err,"\n"|
|00002390| 29 3b 0a 09 09 65 78 69 | 74 28 31 29 3b 0a 09 7d |);...exi|t(1);..}|
|000023a0| 0a 09 65 6c 73 65 20 69 | 66 20 28 6f 70 74 69 6f |..else i|f (optio|
|000023b0| 6e 3e 3d 27 30 27 20 26 | 26 20 6f 70 74 69 6f 6e |n>='0' &|& option|
|000023c0| 3c 3d 27 30 27 2b 63 6f | 75 6e 74 29 7b 0a 09 09 |<='0'+co|unt){...|
|000023d0| 2f 2a 20 74 68 65 79 20 | 68 61 76 65 20 72 65 71 |/* they |have req|
|000023e0| 75 65 73 74 65 64 20 61 | 20 66 69 6c 65 20 62 79 |uested a| file by|
|000023f0| 20 69 74 27 73 20 6e 75 | 6d 62 65 72 20 2a 2f 0a | it's nu|mber */.|
|00002400| 09 09 6f 70 74 69 6f 6e | 3d 6f 70 74 69 6f 6e 2d |..option|=option-|
|00002410| 27 30 27 3b 0a 09 09 66 | 70 72 69 6e 74 66 28 73 |'0';...f|printf(s|
|00002420| 74 64 65 72 72 2c 22 25 | 73 5c 6e 22 2c 68 69 73 |tderr,"%|s\n",his|
|00002430| 74 5b 6f 70 74 69 6f 6e | 5d 29 3b 0a 09 09 73 70 |t[option|]);...sp|
|00002440| 72 69 6e 74 66 28 61 72 | 67 2c 22 25 73 22 2c 68 |rintf(ar|g,"%s",h|
|00002450| 69 73 74 5b 6f 70 74 69 | 6f 6e 5d 29 3b 0a 09 7d |ist[opti|on]);..}|
|00002460| 0a 09 65 6c 73 65 7b 0a | 09 09 2f 2a 20 0a 09 09 |..else{.|../* ...|
|00002470| 20 20 20 6c 6f 6f 6b 73 | 20 6c 69 6b 65 20 74 68 | looks| like th|
|00002480| 65 79 20 77 61 6e 74 20 | 74 6f 20 6e 61 6d 65 20 |ey want |to name |
|00002490| 61 20 73 70 65 63 69 66 | 69 63 20 66 69 6c 65 2e |a specif|ic file.|
|000024a0| 20 65 63 68 6f 20 74 68 | 65 20 0a 09 09 20 20 20 | echo th|e ... |
|000024b0| 63 68 61 72 61 63 74 65 | 72 73 20 62 61 63 6b 20 |characte|rs back |
|000024c0| 74 6f 20 74 68 65 20 73 | 63 72 65 65 6e 2e 0a 09 |to the s|creen...|
|000024d0| 09 2a 2f 0a 09 09 66 70 | 72 69 6e 74 66 28 73 74 |.*/...fp|rintf(st|
|000024e0| 64 65 72 72 2c 22 25 63 | 22 2c 6f 70 74 69 6f 6e |derr,"%c|",option|
|000024f0| 29 3b 0a 09 09 61 72 67 | 5b 30 5d 3d 6f 70 74 69 |);...arg|[0]=opti|
|00002500| 6f 6e 3b 0a 09 09 69 3d | 31 3b 0a 09 09 77 68 69 |on;...i=|1;...whi|
|00002510| 6c 65 20 28 28 61 72 67 | 5b 69 5d 3d 67 65 74 63 |le ((arg|[i]=getc|
|00002520| 28 73 74 64 69 6e 29 29 | 21 3d 27 5c 6e 27 29 7b |(stdin))|!='\n'){|
|00002530| 0a 09 09 09 69 2b 2b 3b | 0a 09 09 7d 0a 09 09 61 |....i++;|...}...a|
|00002540| 72 67 5b 69 5d 3d 27 5c | 30 27 3b 0a 09 09 6f 70 |rg[i]='\|0';...op|
|00002550| 74 69 6f 6e 3d 63 6f 75 | 6e 74 2d 31 3b 09 09 2f |tion=cou|nt-1;../|
|00002560| 2a 20 61 20 6b 6c 75 64 | 67 65 20 66 6f 72 20 74 |* a klud|ge for t|
|00002570| 68 65 20 68 69 73 74 6f | 72 79 20 72 65 2d 6d 61 |he histo|ry re-ma|
|00002580| 6b 65 20 74 6f 20 66 6f | 6c 6c 6f 77 20 2a 2f 0a |ke to fo|llow */.|
|00002590| 0a 09 09 2f 2a 20 73 65 | 65 69 6e 67 20 61 73 20 |.../* se|eing as |
|000025a0| 74 68 65 79 20 74 79 70 | 65 64 20 69 6e 20 74 68 |they typ|ed in th|
|000025b0| 65 20 6e 61 6d 65 2c 20 | 74 72 79 20 61 6e 64 20 |e name, |try and |
|000025c0| 68 65 6c 70 20 77 69 74 | 68 20 73 70 65 6c 6c 69 |help wit|h spelli|
|000025d0| 6e 67 20 2a 2f 0a 09 09 | 73 70 65 6c 6c 5f 68 65 |ng */...|spell_he|
|000025e0| 6c 70 28 29 3b 0a 09 7d | 0a 0a 09 2f 2a 20 72 65 |lp();..}|.../* re|
|000025f0| 62 75 69 6c 64 20 74 68 | 65 20 68 69 73 74 6f 72 |build th|e histor|
|00002600| 79 20 77 69 74 68 20 74 | 68 65 20 73 65 6c 65 63 |y with t|he selec|
|00002610| 74 65 64 20 6e 61 6d 65 | 20 61 74 20 74 68 65 20 |ted name| at the |
|00002620| 62 6f 74 74 6f 6d 20 2a | 2f 0a 09 72 65 63 6f 6e |bottom *|/..recon|
|00002630| 73 74 72 75 63 74 28 6f | 70 74 69 6f 6e 2d 31 2c |struct(o|ption-1,|
|00002640| 63 6f 75 6e 74 2c 64 6f | 74 73 74 72 69 6e 67 29 |count,do|tstring)|
|00002650| 3b 0a 7d 0a 0a 46 49 4c | 45 20 2a 0a 67 65 74 5f |;.}..FIL|E *.get_|
|00002660| 74 65 6d 70 28 29 0a 7b | 0a 09 2f 2a 20 67 65 74 |temp().{|../* get|
|00002670| 20 6f 75 72 73 65 6c 76 | 65 73 20 61 20 74 65 6d | ourselv|es a tem|
|00002680| 70 6f 72 61 72 79 20 66 | 69 6c 65 20 66 6f 72 20 |porary f|ile for |
|00002690| 74 68 65 20 72 65 63 6f | 6e 73 74 72 75 63 74 65 |the reco|nstructe|
|000026a0| 64 20 68 69 73 74 6f 72 | 79 20 2a 2f 0a 09 46 49 |d histor|y */..FI|
|000026b0| 4c 45 20 2a 66 70 2c 2a | 66 6f 70 65 6e 28 29 3b |LE *fp,*|fopen();|
|000026c0| 0a 0a 09 6d 6b 74 65 6d | 70 28 74 6d 70 5f 66 69 |...mktem|p(tmp_fi|
|000026d0| 6c 65 29 3b 0a 09 69 66 | 20 28 28 66 70 3d 66 6f |le);..if| ((fp=fo|
|000026e0| 70 65 6e 28 74 6d 70 5f | 66 69 6c 65 2c 22 77 22 |pen(tmp_|file,"w"|
|000026f0| 29 29 3d 3d 4e 55 4c 4c | 29 7b 0a 09 09 70 65 72 |))==NULL|){...per|
|00002700| 72 6f 72 28 74 6d 70 5f | 66 69 6c 65 29 3b 0a 09 |ror(tmp_|file);..|
|00002710| 09 65 78 69 74 28 31 29 | 3b 0a 09 7d 0a 09 72 65 |.exit(1)|;..}..re|
|00002720| 74 75 72 6e 28 66 70 29 | 3b 0a 7d 0a 0a 63 6c 6f |turn(fp)|;.}..clo|
|00002730| 73 65 5f 74 65 6d 70 28 | 66 70 2c 66 69 6c 65 6e |se_temp(|fp,filen|
|00002740| 61 6d 65 29 0a 46 49 4c | 45 20 2a 66 70 3b 0a 63 |ame).FIL|E *fp;.c|
|00002750| 68 61 72 20 2a 66 69 6c | 65 6e 61 6d 65 3b 0a 7b |har *fil|ename;.{|
|00002760| 0a 09 2f 2a 20 6d 6f 76 | 65 20 74 68 65 20 74 65 |../* mov|e the te|
|00002770| 6d 70 6f 72 61 72 79 20 | 66 69 6c 65 20 74 6f 20 |mporary |file to |
|00002780| 62 65 20 74 68 65 20 6e | 65 77 20 68 69 73 74 6f |be the n|ew histo|
|00002790| 72 79 20 2a 2f 0a 09 46 | 49 4c 45 20 2a 66 63 6c |ry */..F|ILE *fcl|
|000027a0| 6f 73 65 28 29 3b 0a 09 | 63 68 61 72 20 64 69 72 |ose();..|char dir|
|000027b0| 62 75 66 66 65 72 5b 48 | 46 49 4c 45 4c 45 4e 5d |buffer[H|FILELEN]|
|000027c0| 3b 0a 09 63 68 61 72 20 | 2a 66 70 74 72 3b 0a 0a |;..char |*fptr;..|
|000027d0| 09 69 66 20 28 66 63 6c | 6f 73 65 28 66 70 29 3d |.if (fcl|ose(fp)=|
|000027e0| 3d 28 46 49 4c 45 20 2a | 29 45 4f 46 29 7b 0a 09 |=(FILE *|)EOF){..|
|000027f0| 09 66 70 72 69 6e 74 66 | 28 73 74 64 65 72 72 2c |.fprintf|(stderr,|
|00002800| 22 43 6f 75 6c 64 20 6e | 6f 74 20 63 6c 6f 73 65 |"Could n|ot close|
|00002810| 20 25 73 5c 6e 22 2c 74 | 6d 70 5f 66 69 6c 65 29 | %s\n",t|mp_file)|
|00002820| 3b 0a 09 09 65 78 69 74 | 28 31 29 3b 0a 09 7d 0a |;...exit|(1);..}.|
|00002830| 0a 09 73 74 72 63 70 79 | 28 64 69 72 62 75 66 66 |..strcpy|(dirbuff|
|00002840| 65 72 2c 20 66 69 6c 65 | 6e 61 6d 65 29 3b 0a 09 |er, file|name);..|
|00002850| 69 66 20 28 28 66 70 74 | 72 3d 72 69 6e 64 65 78 |if ((fpt|r=rindex|
|00002860| 28 64 69 72 62 75 66 66 | 65 72 2c 27 2f 27 29 29 |(dirbuff|er,'/'))|
|00002870| 3d 3d 30 29 7b 0a 09 09 | 73 74 72 63 70 79 28 64 |==0){...|strcpy(d|
|00002880| 69 72 62 75 66 66 65 72 | 2c 64 6f 74 73 74 72 69 |irbuffer|,dotstri|
|00002890| 6e 67 29 3b 0a 09 09 66 | 70 74 72 20 3d 20 26 64 |ng);...f|ptr = &d|
|000028a0| 69 72 62 75 66 66 65 72 | 5b 31 5d 3b 0a 09 7d 0a |irbuffer|[1];..}.|
|000028b0| 09 73 70 72 69 6e 74 66 | 28 66 70 74 72 2c 22 2f |.sprintf|(fptr,"/|
|000028c0| 25 73 22 2c 20 48 49 53 | 54 29 3b 0a 09 09 0a 09 |%s", HIS|T);.....|
|000028d0| 69 66 20 28 72 65 6e 61 | 6d 65 28 74 6d 70 5f 66 |if (rena|me(tmp_f|
|000028e0| 69 6c 65 2c 64 69 72 62 | 75 66 66 65 72 29 21 3d |ile,dirb|uffer)!=|
|000028f0| 30 29 7b 0a 09 09 70 65 | 72 72 6f 72 28 22 72 65 |0){...pe|rror("re|
|00002900| 6e 61 6d 65 22 29 3b 0a | 09 09 65 78 69 74 28 31 |name");.|..exit(1|
|00002910| 29 3b 0a 09 7d 0a 7d 0a | 0a 73 65 74 5f 74 65 72 |);..}.}.|.set_ter|
|00002920| 6d 28 29 0a 7b 0a 09 2f | 2a 20 67 6f 20 69 6e 74 |m().{../|* go int|
|00002930| 6f 20 63 62 72 65 61 6b | 20 61 6e 64 20 6e 6f 20 |o cbreak| and no |
|00002940| 65 63 68 6f 20 6d 6f 64 | 65 20 2a 2f 0a 23 69 66 |echo mod|e */.#if|
|00002950| 64 65 66 20 73 79 73 56 | 0a 09 73 74 72 75 63 74 |def sysV|..struct|
|00002960| 20 74 65 72 6d 69 6f 09 | 62 6c 6b 3b 0a 0a 09 69 | termio.|blk;...i|
|00002970| 6f 63 74 6c 28 30 2c 20 | 54 43 47 45 54 41 2c 20 |octl(0, |TCGETA, |
|00002980| 26 62 6c 6b 29 3b 0a 09 | 6f 6c 64 62 6c 6b 20 3d |&blk);..|oldblk =|
|00002990| 20 62 6c 6b 3b 0a 09 72 | 75 62 6f 75 74 20 3d 20 | blk;..r|ubout = |
|000029a0| 62 6c 6b 2e 63 5f 63 63 | 5b 56 45 52 41 53 45 5d |blk.c_cc|[VERASE]|
|000029b0| 3b 0a 09 62 6c 6b 2e 63 | 5f 6c 66 6c 61 67 20 26 |;..blk.c|_lflag &|
|000029c0| 3d 20 7e 28 49 43 41 4e | 4f 4e 7c 45 43 48 4f 7c |= ~(ICAN|ON|ECHO||
|000029d0| 45 43 48 4f 4e 4c 29 3b | 0a 09 62 6c 6b 2e 63 5f |ECHONL);|..blk.c_|
|000029e0| 63 63 5b 56 4d 49 4e 5d | 20 3d 20 31 3b 0a 09 62 |cc[VMIN]| = 1;..b|
|000029f0| 6c 6b 2e 63 5f 63 63 5b | 56 54 49 4d 45 5d 20 3d |lk.c_cc[|VTIME] =|
|00002a00| 20 30 3b 0a 09 69 6f 63 | 74 6c 28 30 2c 20 54 43 | 0;..ioc|tl(0, TC|
|00002a10| 53 45 54 41 2c 20 26 62 | 6c 6b 29 3b 0a 23 65 6c |SETA, &b|lk);.#el|
|00002a20| 73 65 0a 09 73 74 72 75 | 63 74 20 73 67 74 74 79 |se..stru|ct sgtty|
|00002a30| 62 09 62 6c 6b 3b 0a 0a | 09 67 74 74 79 28 30 2c |b.blk;..|.gtty(0,|
|00002a40| 20 26 62 6c 6b 29 3b 0a | 09 6f 6c 64 62 6c 6b 20 | &blk);.|.oldblk |
|00002a50| 3d 20 62 6c 6b 3b 0a 09 | 72 75 62 6f 75 74 20 3d |= blk;..|rubout =|
|00002a60| 20 62 6c 6b 2e 73 67 5f | 65 72 61 73 65 3b 0a 09 | blk.sg_|erase;..|
|00002a70| 62 6c 6b 2e 73 67 5f 66 | 6c 61 67 73 20 7c 3d 20 |blk.sg_f|lags |= |
|00002a80| 43 42 52 45 41 4b 3b 0a | 09 62 6c 6b 2e 73 67 5f |CBREAK;.|.blk.sg_|
|00002a90| 66 6c 61 67 73 20 5e 3d | 20 45 43 48 4f 3b 0a 09 |flags ^=| ECHO;..|
|00002aa0| 73 74 74 79 28 30 2c 20 | 26 62 6c 6b 29 3b 0a 23 |stty(0, |&blk);.#|
|00002ab0| 65 6e 64 69 66 20 73 79 | 73 56 0a 09 74 65 72 6d |endif sy|sV..term|
|00002ac0| 5f 6d 65 73 73 79 20 3d | 20 31 3b 0a 7d 0a 0a 75 |_messy =| 1;.}..u|
|00002ad0| 6e 73 65 74 5f 74 65 72 | 6d 28 29 0a 7b 0a 09 2f |nset_ter|m().{../|
|00002ae0| 2a 20 67 65 74 20 6f 75 | 74 20 6f 66 20 63 62 72 |* get ou|t of cbr|
|00002af0| 65 61 6b 20 61 6e 64 20 | 6e 6f 20 65 63 68 6f 20 |eak and |no echo |
|00002b00| 2a 2f 0a 09 69 66 20 28 | 74 65 72 6d 5f 6d 65 73 |*/..if (|term_mes|
|00002b10| 73 79 29 20 7b 0a 23 69 | 66 64 65 66 20 73 79 73 |sy) {.#i|fdef sys|
|00002b20| 56 0a 09 09 69 6f 63 74 | 6c 28 30 2c 20 54 43 53 |V...ioct|l(0, TCS|
|00002b30| 45 54 41 2c 20 26 6f 6c | 64 62 6c 6b 29 3b 0a 23 |ETA, &ol|dblk);.#|
|00002b40| 65 6c 73 65 0a 09 09 73 | 74 74 79 28 30 2c 20 26 |else...s|tty(0, &|
|00002b50| 6f 6c 64 62 6c 6b 29 3b | 0a 23 65 6e 64 69 66 20 |oldblk);|.#endif |
|00002b60| 73 79 73 56 0a 09 09 74 | 65 72 6d 5f 6d 65 73 73 |sysV...t|erm_mess|
|00002b70| 79 20 3d 20 30 3b 0a 09 | 7d 0a 7d 0a 0a 6d 61 74 |y = 0;..|}.}..mat|
|00002b80| 63 68 28 61 72 67 75 6d | 65 6e 74 2c 70 61 74 74 |ch(argum|ent,patt|
|00002b90| 65 72 6e 29 0a 63 68 61 | 72 09 2a 61 72 67 75 6d |ern).cha|r.*argum|
|00002ba0| 65 6e 74 3b 0a 63 68 61 | 72 09 2a 70 61 74 74 65 |ent;.cha|r.*patte|
|00002bb0| 72 6e 3b 0a 7b 0a 09 2f | 2a 0a 09 20 20 20 62 6f |rn;.{../|*.. bo|
|00002bc0| 6e 65 68 65 61 64 65 64 | 20 62 75 74 20 65 61 73 |neheaded| but eas|
|00002bd0| 79 20 70 61 74 74 65 72 | 6e 20 6d 61 74 63 68 65 |y patter|n matche|
|00002be0| 72 2e 20 6a 75 73 74 20 | 73 65 65 20 69 66 20 74 |r. just |see if t|
|00002bf0| 68 65 20 27 70 61 74 74 | 65 72 6e 27 0a 09 20 20 |he 'patt|ern'.. |
|00002c00| 20 65 78 69 73 74 73 20 | 61 6e 79 77 68 65 72 65 | exists |anywhere|
|00002c10| 20 69 6e 20 74 68 65 20 | 27 61 72 67 75 6d 65 6e | in the |'argumen|
|00002c20| 74 27 2e 20 62 6f 79 65 | 72 2d 6d 6f 6f 72 65 20 |t'. boye|r-moore |
|00002c30| 77 68 6f 3f 0a 09 2a 2f | 0a 09 72 65 67 69 73 74 |who?..*/|..regist|
|00002c40| 65 72 20 6c 65 6e 67 74 | 68 3d 73 74 72 6c 65 6e |er lengt|h=strlen|
|00002c50| 28 70 61 74 74 65 72 6e | 29 3b 0a 0a 09 77 68 69 |(pattern|);...whi|
|00002c60| 6c 65 20 28 73 74 72 6c | 65 6e 28 61 72 67 75 6d |le (strl|en(argum|
|00002c70| 65 6e 74 29 3e 3d 6c 65 | 6e 67 74 68 29 7b 0a 09 |ent)>=le|ngth){..|
|00002c80| 09 69 66 20 28 21 73 74 | 72 6e 63 6d 70 28 61 72 |.if (!st|rncmp(ar|
|00002c90| 67 75 6d 65 6e 74 2b 2b | 2c 70 61 74 74 65 72 6e |gument++|,pattern|
|00002ca0| 2c 6c 65 6e 67 74 68 29 | 29 7b 0a 09 09 09 72 65 |,length)|){....re|
|00002cb0| 74 75 72 6e 28 31 29 3b | 0a 09 09 7d 0a 09 7d 0a |turn(1);|...}..}.|
|00002cc0| 09 72 65 74 75 72 6e 28 | 30 29 3b 0a 7d 0a 0a 66 |.return(|0);.}..f|
|00002cd0| 69 6e 64 5f 6d 61 74 63 | 68 28 70 61 74 74 65 72 |ind_matc|h(patter|
|00002ce0| 6e 29 0a 63 68 61 72 20 | 2a 70 61 74 74 65 72 6e |n).char |*pattern|
|00002cf0| 3b 0a 7b 0a 09 2f 2a 0a | 09 20 20 20 66 69 6e 64 |;.{../*.|. find|
|00002d00| 20 74 68 65 20 6e 61 6d | 65 20 69 6e 20 74 68 65 | the nam|e in the|
|00002d10| 20 68 69 73 74 6f 72 79 | 20 6c 69 73 74 20 74 68 | history| list th|
|00002d20| 61 74 20 63 6f 6e 74 61 | 69 6e 73 20 74 68 65 20 |at conta|ins the |
|00002d30| 27 70 61 74 74 65 72 6e | 27 2e 0a 09 20 20 20 69 |'pattern|'... i|
|00002d40| 66 20 69 74 20 65 78 69 | 73 74 73 20 74 68 65 6e |f it exi|sts then|
|00002d50| 20 70 75 74 20 69 74 20 | 69 6e 74 6f 20 74 68 65 | put it |into the|
|00002d60| 20 27 61 72 67 27 20 76 | 61 72 69 61 62 6c 65 20 | 'arg' v|ariable |
|00002d70| 61 6e 64 20 6f 74 68 65 | 72 77 69 73 65 0a 09 20 |and othe|rwise.. |
|00002d80| 20 20 61 6e 6e 6f 75 6e | 63 65 20 74 68 61 74 20 | announ|ce that |
|00002d90| 61 20 6d 61 74 63 68 20 | 63 6f 75 6c 64 6e 27 74 |a match |couldn't|
|00002da0| 20 62 65 20 66 6f 75 6e | 64 20 61 6e 64 20 6c 65 | be foun|d and le|
|00002db0| 61 76 65 2e 0a 09 2a 2f | 0a 09 72 65 67 69 73 74 |ave...*/|..regist|
|00002dc0| 65 72 20 63 6f 75 6e 74 | 3b 0a 09 72 65 67 69 73 |er count|;..regis|
|00002dd0| 74 65 72 20 69 3b 0a 0a | 09 2f 2a 20 72 65 61 64 |ter i;..|./* read|
|00002de0| 20 61 6e 64 20 73 70 6c | 69 74 20 74 68 65 20 68 | and spl|it the h|
|00002df0| 69 73 74 6f 72 79 20 66 | 69 6c 65 20 2a 2f 0a 09 |istory f|ile */..|
|00002e00| 72 65 61 64 5f 68 69 73 | 74 28 64 6f 74 73 74 72 |read_his|t(dotstr|
|00002e10| 69 6e 67 29 3b 0a 09 63 | 6f 75 6e 74 3d 73 70 6c |ing);..c|ount=spl|
|00002e20| 69 74 5f 68 69 73 74 28 | 29 3b 0a 0a 09 2f 2a 20 |it_hist(|);.../* |
|00002e30| 74 72 79 20 66 6f 72 20 | 61 20 6d 61 74 63 68 20 |try for |a match |
|00002e40| 77 69 74 68 20 65 61 63 | 68 20 66 69 6c 65 20 69 |with eac|h file i|
|00002e50| 6e 20 74 75 72 6e 20 28 | 6e 6f 74 65 20 74 68 61 |n turn (|note tha|
|00002e60| 74 20 77 65 20 61 72 65 | 20 77 6f 72 6b 69 6e 67 |t we are| working|
|00002e70| 0a 09 20 20 20 66 72 6f | 6d 20 6d 6f 73 74 2d 72 |.. fro|m most-r|
|00002e80| 65 63 65 6e 74 6c 79 2d | 75 73 65 64 20 62 61 63 |ecently-|used bac|
|00002e90| 6b 77 61 72 64 73 20 2d | 20 70 72 6f 62 61 62 6c |kwards -| probabl|
|00002ea0| 79 20 61 20 67 6f 6f 64 | 20 74 68 69 6e 67 29 0a |y a good| thing).|
|00002eb0| 09 2a 2f 0a 09 66 6f 72 | 20 28 69 3d 30 3b 69 3c |.*/..for| (i=0;i<|
|00002ec0| 63 6f 75 6e 74 3b 69 2b | 2b 29 7b 0a 09 09 69 66 |count;i+|+){...if|
|00002ed0| 20 28 6d 61 74 63 68 28 | 68 69 73 74 5b 69 5d 2c | (match(|hist[i],|
|00002ee0| 70 61 74 74 65 72 6e 29 | 29 7b 0a 09 09 09 73 70 |pattern)|){....sp|
|00002ef0| 72 69 6e 74 66 28 61 72 | 67 2c 22 25 73 22 2c 68 |rintf(ar|g,"%s",h|
|00002f00| 69 73 74 5b 69 5d 29 3b | 0a 09 09 09 72 65 63 6f |ist[i]);|....reco|
|00002f10| 6e 73 74 72 75 63 74 28 | 69 2c 63 6f 75 6e 74 2c |nstruct(|i,count,|
|00002f20| 64 6f 74 73 74 72 69 6e | 67 29 3b 0a 09 09 09 72 |dotstrin|g);....r|
|00002f30| 65 74 75 72 6e 3b 0a 09 | 09 7d 0a 09 7d 0a 0a 09 |eturn;..|.}..}...|
|00002f40| 2f 2a 20 77 65 20 63 6f | 75 6c 64 6e 27 74 20 6d |/* we co|uldn't m|
|00002f50| 61 74 63 68 20 73 6f 20 | 67 65 74 20 6f 75 74 20 |atch so |get out |
|00002f60| 6f 66 20 68 65 72 65 20 | 2a 2f 0a 09 66 70 72 69 |of here |*/..fpri|
|00002f70| 6e 74 66 28 73 74 64 65 | 72 72 2c 22 55 6e 61 62 |ntf(stde|rr,"Unab|
|00002f80| 6c 65 20 74 6f 20 6d 61 | 74 63 68 20 77 69 74 68 |le to ma|tch with|
|00002f90| 20 5c 22 25 73 5c 22 5c | 6e 22 2c 70 61 74 74 65 | \"%s\"\|n",patte|
|00002fa0| 72 6e 29 3b 0a 09 65 78 | 69 74 28 31 29 3b 0a 7d |rn);..ex|it(1);.}|
|00002fb0| 0a 0a 69 6e 73 65 72 74 | 5f 63 6f 6d 6d 61 6e 64 |..insert|_command|
|00002fc0| 28 63 6f 6d 6d 61 6e 64 | 29 0a 63 68 61 72 20 2a |(command|).char *|
|00002fd0| 63 6f 6d 6d 61 6e 64 3b | 0a 7b 0a 09 2f 2a 0a 09 |command;|.{../*..|
|00002fe0| 20 20 20 74 68 65 79 20 | 77 61 6e 74 20 74 68 65 | they |want the|
|00002ff0| 20 6c 61 73 74 20 66 69 | 6c 65 20 69 6e 20 74 68 | last fi|le in th|
|00003000| 65 20 68 69 73 74 6f 72 | 79 20 62 75 74 20 77 61 |e histor|y but wa|
|00003010| 6e 74 20 74 6f 20 70 72 | 65 63 65 65 64 20 69 74 |nt to pr|eceed it|
|00003020| 0a 09 20 20 20 74 68 69 | 73 20 74 69 6d 65 20 77 |.. thi|s time w|
|00003030| 69 74 68 20 61 20 63 6f | 6d 6d 61 6e 64 20 2d 20 |ith a co|mmand - |
|00003040| 6e 6f 20 70 72 6f 62 6c | 65 6d 73 20 68 65 72 65 |no probl|ems here|
|00003050| 2e 0a 09 2a 2f 0a 09 72 | 65 67 69 73 74 65 72 20 |...*/..r|egister |
|00003060| 63 6f 75 6e 74 3b 0a 09 | 63 68 61 72 20 2a 70 6c |count;..|char *pl|
|00003070| 61 63 65 3b 0a 0a 09 2f | 2a 20 72 65 61 64 20 61 |ace;.../|* read a|
|00003080| 6e 64 20 73 70 6c 69 74 | 20 74 68 65 20 68 69 73 |nd split| the his|
|00003090| 74 6f 72 79 20 2a 2f 0a | 09 72 65 61 64 5f 68 69 |tory */.|.read_hi|
|000030a0| 73 74 28 64 6f 74 73 74 | 72 69 6e 67 29 3b 0a 09 |st(dotst|ring);..|
|000030b0| 63 6f 75 6e 74 3d 73 70 | 6c 69 74 5f 68 69 73 74 |count=sp|lit_hist|
|000030c0| 28 29 3b 0a 09 0a 09 2f | 2a 20 0a 09 20 20 20 69 |();..../|* .. i|
|000030d0| 66 20 74 68 65 72 65 20 | 77 61 73 20 61 6c 72 65 |f there |was alre|
|000030e0| 61 64 79 20 61 20 63 6f | 6d 6d 61 6e 64 20 74 68 |ady a co|mmand th|
|000030f0| 65 72 65 20 28 69 6e 64 | 69 63 61 74 65 64 20 62 |ere (ind|icated b|
|00003100| 79 20 61 20 27 2b 27 29 | 20 74 68 65 6e 20 77 65 |y a '+')| then we|
|00003110| 0a 09 20 20 20 77 61 6e | 74 20 74 6f 20 67 65 74 |.. wan|t to get|
|00003120| 20 72 69 64 20 6f 66 20 | 69 74 2e 20 69 66 20 74 | rid of |it. if t|
|00003130| 68 65 72 65 20 69 73 20 | 61 20 27 2b 27 20 62 75 |here is |a '+' bu|
|00003140| 74 20 6e 6f 20 27 20 27 | 20 61 66 74 65 72 20 69 |t no ' '| after i|
|00003150| 74 20 74 68 65 6e 0a 09 | 20 20 20 74 68 65 20 68 |t then..| the h|
|00003160| 69 73 74 6f 72 79 20 66 | 69 6c 65 20 69 73 20 69 |istory f|ile is i|
|00003170| 6e 20 64 69 73 61 72 72 | 61 79 20 61 6e 64 20 77 |n disarr|ay and w|
|00003180| 65 20 77 69 6c 6c 20 6e | 6f 74 20 74 72 79 20 74 |e will n|ot try t|
|00003190| 6f 20 72 65 63 6f 76 65 | 72 0a 09 2a 2f 0a 09 69 |o recove|r..*/..i|
|000031a0| 66 20 28 2a 68 69 73 74 | 5b 30 5d 3d 3d 27 2b 27 |f (*hist|[0]=='+'|
|000031b0| 29 7b 0a 09 09 69 66 20 | 28 28 70 6c 61 63 65 3d |){...if |((place=|
|000031c0| 69 6e 64 65 78 28 68 69 | 73 74 5b 30 5d 2c 27 20 |index(hi|st[0],' |
|000031d0| 27 29 29 3d 3d 4e 55 4c | 4c 29 7b 0a 09 09 09 66 |'))==NUL|L){....f|
|000031e0| 70 72 69 6e 74 66 28 22 | 53 65 72 69 6f 75 73 20 |printf("|Serious |
|000031f0| 77 65 69 72 64 65 6e 73 | 73 20 69 6e 20 69 6e 73 |weirdens|s in ins|
|00003200| 65 72 74 5f 63 6f 6d 6d | 61 6e 64 5c 6e 22 29 3b |ert_comm|and\n");|
|00003210| 0a 09 09 09 65 78 69 74 | 28 31 29 3b 0a 09 09 7d |....exit|(1);...}|
|00003220| 0a 09 09 2f 2a 20 6d 6f | 76 65 20 6f 76 65 72 20 |.../* mo|ve over |
|00003230| 77 68 69 74 65 20 73 70 | 61 63 65 20 2d 20 69 66 |white sp|ace - if|
|00003240| 20 74 68 65 72 65 20 69 | 73 20 61 6e 79 20 2a 2f | there i|s any */|
|00003250| 0a 09 09 77 68 69 6c 65 | 20 28 2a 70 6c 61 63 65 |...while| (*place|
|00003260| 3d 3d 27 20 27 7c 7c 2a | 70 6c 61 63 65 3d 3d 27 |==' '||*|place=='|
|00003270| 5c 74 27 29 7b 0a 09 09 | 09 70 6c 61 63 65 2b 2b |\t'){...|.place++|
|00003280| 3b 0a 09 09 7d 0a 09 7d | 0a 09 65 6c 73 65 7b 0a |;...}..}|..else{.|
|00003290| 09 09 2f 2a 20 74 68 65 | 72 65 20 77 61 73 20 6e |../* the|re was n|
|000032a0| 6f 20 63 6f 6d 6d 61 6e | 64 20 70 72 65 63 65 65 |o comman|d precee|
|000032b0| 64 69 6e 67 20 74 68 65 | 20 6c 61 73 74 20 66 69 |ding the| last fi|
|000032c0| 6c 65 20 69 6e 20 74 68 | 65 20 68 69 73 74 6f 72 |le in th|e histor|
|000032d0| 79 20 2a 2f 0a 09 09 70 | 6c 61 63 65 3d 68 69 73 |y */...p|lace=his|
|000032e0| 74 5b 30 5d 3b 0a 09 7d | 0a 0a 09 2f 2a 20 70 75 |t[0];..}|.../* pu|
|000032f0| 74 20 74 68 65 20 6e 65 | 77 20 63 6f 6d 6d 61 6e |t the ne|w comman|
|00003300| 64 20 61 6e 64 20 74 68 | 65 20 66 69 6c 65 6e 61 |d and th|e filena|
|00003310| 6d 65 20 69 6e 74 6f 20 | 27 61 72 67 27 20 2a 2f |me into |'arg' */|
|00003320| 0a 09 73 70 72 69 6e 74 | 66 28 61 72 67 2c 22 25 |..sprint|f(arg,"%|
|00003330| 73 20 25 73 22 2c 63 6f | 6d 6d 61 6e 64 2c 70 6c |s %s",co|mmand,pl|
|00003340| 61 63 65 29 3b 0a 0a 09 | 2f 2a 20 72 65 62 75 69 |ace);...|/* rebui|
|00003350| 6c 64 20 74 68 65 20 68 | 69 73 74 6f 72 79 20 77 |ld the h|istory w|
|00003360| 69 74 68 20 74 68 65 20 | 73 65 6c 65 63 74 65 64 |ith the |selected|
|00003370| 20 63 6f 6d 6d 61 6e 64 | 20 61 6e 64 20 6e 61 6d | command| and nam|
|00003380| 65 20 61 74 20 74 68 65 | 20 62 6f 74 74 6f 6d 20 |e at the| bottom |
|00003390| 2a 2f 0a 09 72 65 63 6f | 6e 73 74 72 75 63 74 28 |*/..reco|nstruct(|
|000033a0| 30 2c 63 6f 75 6e 74 2c | 64 6f 74 73 74 72 69 6e |0,count,|dotstrin|
|000033b0| 67 29 3b 0a 7d 0a 0a 72 | 65 63 6f 6e 73 74 72 75 |g);.}..r|econstru|
|000033c0| 63 74 28 65 78 63 65 70 | 74 2c 63 6f 75 6e 74 2c |ct(excep|t,count,|
|000033d0| 64 69 72 6e 61 6d 65 29 | 0a 69 6e 74 09 65 78 63 |dirname)|.int.exc|
|000033e0| 65 70 74 3b 0a 69 6e 74 | 09 63 6f 75 6e 74 3b 0a |ept;.int|.count;.|
|000033f0| 63 68 61 72 09 2a 64 69 | 72 6e 61 6d 65 3b 0a 7b |char.*di|rname;.{|
|00003400| 0a 09 2f 2a 20 0a 09 20 | 20 20 72 65 63 6f 6e 73 |../* .. | recons|
|00003410| 74 72 75 63 74 20 68 69 | 73 74 6f 72 79 20 66 69 |truct hi|story fi|
|00003420| 6c 65 20 65 78 63 65 70 | 74 69 6e 67 20 74 68 65 |le excep|ting the|
|00003430| 20 27 65 78 63 65 70 74 | 27 20 6c 61 73 74 2e 0a | 'except|' last..|
|00003440| 09 20 20 20 73 6f 20 6a | 75 73 74 20 63 6f 70 79 |. so j|ust copy|
|00003450| 20 61 6c 6c 20 6c 69 6e | 65 73 20 62 75 74 20 74 | all lin|es but t|
|00003460| 68 65 20 27 65 78 63 65 | 70 74 27 74 68 20 6c 61 |he 'exce|pt'th la|
|00003470| 73 74 20 61 6e 64 20 74 | 68 65 6e 20 70 75 74 20 |st and t|hen put |
|00003480| 69 6e 20 27 61 72 67 27 | 0a 09 20 20 20 77 68 69 |in 'arg'|.. whi|
|00003490| 63 68 20 63 6f 6e 74 61 | 69 6e 73 20 74 68 65 20 |ch conta|ins the |
|000034a0| 6e 65 77 20 6c 69 6e 65 | 20 66 6f 72 20 74 68 65 |new line| for the|
|000034b0| 20 68 69 73 74 6f 72 79 | 0a 09 2a 2f 0a 09 72 65 | history|..*/..re|
|000034c0| 67 69 73 74 65 72 20 69 | 3b 0a 09 46 49 4c 45 20 |gister i|;..FILE |
|000034d0| 2a 74 76 2c 2a 67 65 74 | 5f 74 65 6d 70 28 29 3b |*tv,*get|_temp();|
|000034e0| 0a 09 63 68 61 72 20 2a | 66 70 74 72 3b 0a 0a 09 |..char *|fptr;...|
|000034f0| 2f 2a 20 67 65 74 20 61 | 20 74 65 6d 70 6f 72 61 |/* get a| tempora|
|00003500| 72 79 20 66 69 6c 65 20 | 2a 2f 0a 09 74 76 3d 67 |ry file |*/..tv=g|
|00003510| 65 74 5f 74 65 6d 70 28 | 29 3b 0a 0a 09 2f 2a 20 |et_temp(|);.../* |
|00003520| 67 72 61 62 20 74 61 69 | 6c 20 6f 66 20 66 69 6c |grab tai|l of fil|
|00003530| 65 20 6e 61 6d 65 2e 20 | 2a 2f 0a 09 69 66 20 28 |e name. |*/..if (|
|00003540| 66 70 74 72 3d 72 69 6e | 64 65 78 28 61 72 67 2c |fptr=rin|dex(arg,|
|00003550| 27 2f 27 29 29 20 66 70 | 74 72 2b 2b 3b 0a 09 65 |'/')) fp|tr++;..e|
|00003560| 6c 73 65 20 66 70 74 72 | 3d 61 72 67 3b 0a 0a 09 |lse fptr|=arg;...|
|00003570| 2f 2a 20 70 75 74 20 69 | 6e 20 74 68 65 20 6c 69 |/* put i|n the li|
|00003580| 6e 65 20 77 65 20 73 74 | 69 6c 6c 20 77 61 6e 74 |ne we st|ill want|
|00003590| 20 2d 20 69 67 6e 6f 72 | 69 6e 67 20 64 75 70 6c | - ignor|ing dupl|
|000035a0| 69 63 61 74 65 73 20 6f | 66 20 74 68 69 73 20 66 |icates o|f this f|
|000035b0| 69 6c 65 20 2a 2f 0a 09 | 66 6f 72 20 28 69 3d 63 |ile */..|for (i=c|
|000035c0| 6f 75 6e 74 2d 31 3b 69 | 3e 3d 30 3b 69 2d 2d 29 |ount-1;i|>=0;i--)|
|000035d0| 7b 0a 09 09 69 66 20 28 | 69 21 3d 65 78 63 65 70 |{...if (|i!=excep|
|000035e0| 74 20 26 26 20 73 74 72 | 63 6d 70 28 68 69 73 74 |t && str|cmp(hist|
|000035f0| 5b 69 5d 2c 66 70 74 72 | 29 21 3d 30 29 7b 0a 09 |[i],fptr|)!=0){..|
|00003600| 09 09 66 70 72 69 6e 74 | 66 28 74 76 2c 22 25 73 |..fprint|f(tv,"%s|
|00003610| 5c 6e 22 2c 68 69 73 74 | 5b 69 5d 29 3b 0a 09 09 |\n",hist|[i]);...|
|00003620| 7d 0a 09 7d 0a 0a 09 2f | 2a 20 70 75 74 20 69 6e |}..}.../|* put in|
|00003630| 20 74 68 65 20 6e 65 77 | 20 6c 69 6e 65 20 66 72 | the new| line fr|
|00003640| 6f 6d 20 27 61 72 67 27 | 20 2a 2f 0a 09 66 70 72 |om 'arg'| */..fpr|
|00003650| 69 6e 74 66 28 74 76 2c | 22 25 73 5c 6e 22 2c 66 |intf(tv,|"%s\n",f|
|00003660| 70 74 72 29 3b 0a 0a 09 | 2f 2a 20 72 65 6e 61 6d |ptr);...|/* renam|
|00003670| 65 20 74 68 65 20 74 65 | 6d 70 6f 72 61 72 79 20 |e the te|mporary |
|00003680| 74 6f 20 62 65 20 74 68 | 65 20 6e 65 77 20 68 69 |to be th|e new hi|
|00003690| 73 74 6f 72 79 20 66 69 | 6c 65 20 2a 2f 0a 09 63 |story fi|le */..c|
|000036a0| 6c 6f 73 65 5f 74 65 6d | 70 28 74 76 2c 61 72 67 |lose_tem|p(tv,arg|
|000036b0| 29 3b 0a 7d 0a 0a 6e 6f | 72 6d 61 6c 28 73 74 72 |);.}..no|rmal(str|
|000036c0| 69 6e 67 29 0a 63 68 61 | 72 20 2a 73 74 72 69 6e |ing).cha|r *strin|
|000036d0| 67 3b 0a 7b 0a 09 2f 2a | 20 0a 09 20 20 20 61 20 |g;.{../*| .. a |
|000036e0| 6e 6f 72 6d 61 6c 20 66 | 69 6c 65 6e 61 6d 65 20 |normal f|ilename |
|000036f0| 77 61 73 20 66 6f 75 6e | 64 2c 20 70 75 74 20 69 |was foun|d, put i|
|00003700| 74 20 69 6e 74 6f 20 61 | 72 67 2e 20 66 69 72 73 |t into a|rg. firs|
|00003710| 74 20 6f 66 20 61 6c 6c | 20 69 66 20 74 68 65 72 |t of all| if ther|
|00003720| 65 0a 09 20 20 20 69 73 | 20 61 20 68 69 73 74 6f |e.. is| a histo|
|00003730| 72 79 20 61 6e 64 20 74 | 68 65 20 66 69 6c 65 20 |ry and t|he file |
|00003740| 69 73 20 61 6c 72 65 61 | 64 79 20 69 6e 20 69 74 |is alrea|dy in it|
|00003750| 20 28 77 68 69 63 68 20 | 6d 65 61 6e 73 20 74 68 | (which |means th|
|00003760| 65 79 20 63 6f 75 6c 64 | 0a 09 20 20 20 68 61 76 |ey could|.. hav|
|00003770| 65 20 67 6f 74 74 65 6e | 20 74 6f 20 74 68 69 73 |e gotten| to this|
|00003780| 20 66 69 6c 65 20 69 6e | 20 6f 74 68 65 72 20 77 | file in| other w|
|00003790| 61 79 73 29 2c 20 74 68 | 65 6e 20 72 65 63 6f 6e |ays), th|en recon|
|000037a0| 73 74 72 75 63 74 20 74 | 68 65 20 68 69 73 74 6f |struct t|he histo|
|000037b0| 72 79 0a 09 20 20 20 61 | 73 20 74 68 6f 75 67 68 |ry.. a|s though|
|000037c0| 20 74 68 65 79 20 68 61 | 64 2e 20 61 6c 73 6f 20 | they ha|d. also |
|000037d0| 6f 66 66 65 72 20 73 70 | 65 6c 6c 69 6e 67 20 68 |offer sp|elling h|
|000037e0| 65 6c 70 2e 0a 09 2a 2f | 0a 09 72 65 67 69 73 74 |elp...*/|..regist|
|000037f0| 65 72 20 63 6f 75 6e 74 | 3b 0a 09 72 65 67 69 73 |er count|;..regis|
|00003800| 74 65 72 20 69 3b 0a 09 | 63 68 61 72 20 2a 65 64 |ter i;..|char *ed|
|00003810| 69 72 3b 0a 0a 09 2f 2a | 20 70 75 74 20 69 74 20 |ir;.../*| put it |
|00003820| 69 6e 74 6f 20 27 61 72 | 67 27 20 2a 2f 0a 09 73 |into 'ar|g' */..s|
|00003830| 70 72 69 6e 74 66 28 61 | 72 67 2c 22 25 73 22 2c |printf(a|rg,"%s",|
|00003840| 73 74 72 69 6e 67 29 3b | 0a 0a 09 2f 2a 20 69 66 |string);|.../* if|
|00003850| 20 74 68 65 72 65 20 69 | 73 20 61 20 68 69 73 74 | there i|s a hist|
|00003860| 6f 72 79 20 66 69 6c 65 | 20 2a 2f 0a 09 69 66 20 |ory file| */..if |
|00003870| 28 65 64 69 72 3d 67 6f | 74 5f 76 69 28 73 74 72 |(edir=go|t_vi(str|
|00003880| 69 6e 67 29 29 7b 0a 0a | 09 09 2f 2a 20 72 65 61 |ing)){..|../* rea|
|00003890| 64 20 69 74 20 61 6e 64 | 20 73 70 6c 69 74 20 69 |d it and| split i|
|000038a0| 74 20 75 70 20 2a 2f 0a | 09 09 72 65 61 64 5f 68 |t up */.|..read_h|
|000038b0| 69 73 74 28 65 64 69 72 | 29 3b 0a 09 09 63 6f 75 |ist(edir|);...cou|
|000038c0| 6e 74 3d 73 70 6c 69 74 | 5f 68 69 73 74 28 29 3b |nt=split|_hist();|
|000038d0| 0a 0a 09 09 2f 2a 20 69 | 66 20 69 74 20 69 73 20 |..../* i|f it is |
|000038e0| 69 6e 20 74 68 65 20 68 | 69 73 74 6f 72 79 20 74 |in the h|istory t|
|000038f0| 68 65 6e 20 72 65 63 6f | 6e 73 74 72 75 63 74 20 |hen reco|nstruct |
|00003900| 61 6e 64 20 72 65 74 75 | 72 6e 20 2a 2f 0a 09 09 |and retu|rn */...|
|00003910| 66 6f 72 20 28 69 3d 30 | 3b 69 3c 63 6f 75 6e 74 |for (i=0|;i<count|
|00003920| 3b 69 2b 2b 29 7b 0a 09 | 09 09 69 66 20 28 21 73 |;i++){..|..if (!s|
|00003930| 74 72 63 6d 70 28 68 69 | 73 74 5b 69 5d 2c 61 72 |trcmp(hi|st[i],ar|
|00003940| 67 29 29 7b 0a 09 09 09 | 09 72 65 63 6f 6e 73 74 |g)){....|.reconst|
|00003950| 72 75 63 74 28 69 2c 63 | 6f 75 6e 74 2c 20 65 64 |ruct(i,c|ount, ed|
|00003960| 69 72 29 3b 0a 09 09 09 | 09 72 65 74 75 72 6e 3b |ir);....|.return;|
|00003970| 0a 09 09 09 7d 0a 09 09 | 7d 0a 0a 09 09 2f 2a 20 |....}...|}..../* |
|00003980| 69 74 27 73 20 6e 6f 74 | 20 69 6e 20 74 68 65 20 |it's not| in the |
|00003990| 68 69 73 74 6f 72 79 2c | 20 68 65 6c 70 20 77 69 |history,| help wi|
|000039a0| 74 68 20 73 70 65 6c 6c | 69 6e 67 20 74 68 65 6e |th spell|ing then|
|000039b0| 20 72 65 63 6f 6e 73 74 | 72 75 63 74 20 2a 2f 0a | reconst|ruct */.|
|000039c0| 09 09 73 70 65 6c 6c 5f | 68 65 6c 70 28 29 3b 0a |..spell_|help();.|
|000039d0| 09 09 72 65 63 6f 6e 73 | 74 72 75 63 74 28 48 49 |..recons|truct(HI|
|000039e0| 53 54 5f 4c 49 4e 45 53 | 2c 63 6f 75 6e 74 2c 65 |ST_LINES|,count,e|
|000039f0| 64 69 72 29 3b 0a 09 7d | 0a 09 65 6c 73 65 7b 0a |dir);..}|..else{.|
|00003a00| 0a 09 09 2f 2a 20 0a 09 | 09 20 20 20 74 68 65 72 |.../* ..|. ther|
|00003a10| 65 20 69 73 20 6e 6f 20 | 68 69 73 74 6f 72 79 20 |e is no |history |
|00003a20| 61 72 6f 75 6e 64 20 73 | 6f 20 68 65 6c 70 20 77 |around s|o help w|
|00003a30| 69 74 68 20 73 70 65 6c | 6c 69 6e 67 20 61 6e 64 |ith spel|ling and|
|00003a40| 20 73 65 74 20 75 70 20 | 61 20 0a 09 09 20 20 20 | set up |a ... |
|00003a50| 68 69 73 74 6f 72 79 20 | 66 6f 72 20 6e 65 78 74 |history |for next|
|00003a60| 20 74 69 6d 65 2e 0a 09 | 09 2a 2f 0a 09 09 73 70 | time...|.*/...sp|
|00003a70| 65 6c 6c 5f 68 65 6c 70 | 28 29 3b 0a 09 09 6e 65 |ell_help|();...ne|
|00003a80| 77 5f 76 69 28 73 74 72 | 69 6e 67 29 3b 0a 09 7d |w_vi(str|ing);..}|
|00003a90| 0a 0a 7d 0a 0a 6d 75 6c | 74 69 70 6c 65 28 6e 75 |..}..mul|tiple(nu|
|00003aa0| 6d 62 65 72 2c 20 61 72 | 67 73 29 0a 69 6e 74 20 |mber, ar|gs).int |
|00003ab0| 6e 75 6d 62 65 72 3b 0a | 63 68 61 72 20 2a 2a 61 |number;.|char **a|
|00003ac0| 72 67 73 3b 0a 7b 0a 09 | 2f 2a 0a 09 20 20 20 74 |rgs;.{..|/*.. t|
|00003ad0| 68 65 72 65 20 77 65 72 | 65 20 73 65 76 65 72 61 |here wer|e severa|
|00003ae0| 6c 20 6e 61 6d 65 73 20 | 6f 6e 20 74 68 65 20 63 |l names |on the c|
|00003af0| 6f 6d 6d 61 6e 64 20 6c | 69 6e 65 20 73 6f 20 77 |ommand l|ine so w|
|00003b00| 65 20 6a 75 73 74 20 73 | 74 72 63 61 74 20 74 68 |e just s|trcat th|
|00003b10| 65 6d 0a 09 20 20 20 69 | 6e 74 6f 20 74 68 65 20 |em.. i|nto the |
|00003b20| 27 61 72 67 27 20 61 72 | 72 61 79 2e 0a 09 2a 2f |'arg' ar|ray...*/|
|00003b30| 0a 09 72 65 67 69 73 74 | 65 72 20 63 6f 75 6e 74 |..regist|er count|
|00003b40| 3b 0a 09 72 65 67 69 73 | 74 65 72 20 69 3b 0a 09 |;..regis|ter i;..|
|00003b50| 63 68 61 72 20 2a 65 64 | 69 72 3b 0a 0a 09 2a 61 |char *ed|ir;...*a|
|00003b60| 72 67 3d 27 5c 30 27 3b | 0a 09 77 68 69 6c 65 20 |rg='\0';|..while |
|00003b70| 28 2d 2d 6e 75 6d 62 65 | 72 29 7b 0a 09 09 73 74 |(--numbe|r){...st|
|00003b80| 72 63 61 74 28 61 72 67 | 2c 2a 2b 2b 61 72 67 73 |rcat(arg|,*++args|
|00003b90| 29 3b 0a 09 09 69 66 20 | 28 6e 75 6d 62 65 72 3e |);...if |(number>|
|00003ba0| 31 29 7b 0a 09 09 09 73 | 74 72 63 61 74 28 61 72 |1){....s|trcat(ar|
|00003bb0| 67 2c 22 20 22 29 3b 0a | 09 09 7d 0a 09 7d 0a 0a |g," ");.|..}..}..|
|00003bc0| 09 2f 2a 0a 09 20 20 20 | 6e 6f 77 20 69 66 20 74 |./*.. |now if t|
|00003bd0| 68 65 72 65 20 69 73 20 | 61 20 68 69 73 74 6f 72 |here is |a histor|
|00003be0| 79 20 66 69 6c 65 20 61 | 6e 64 20 77 65 20 63 61 |y file a|nd we ca|
|00003bf0| 6e 20 66 69 6e 64 20 61 | 6e 20 69 64 65 6e 74 69 |n find a|n identi|
|00003c00| 63 61 6c 20 6c 69 6e 65 | 0a 09 20 20 20 74 68 65 |cal line|.. the|
|00003c10| 6e 20 72 65 63 6f 6e 73 | 74 72 75 63 74 20 77 69 |n recons|truct wi|
|00003c20| 74 68 20 74 68 61 74 20 | 6c 69 6e 65 20 61 74 20 |th that |line at |
|00003c30| 74 68 65 20 62 6f 74 74 | 6f 6d 2e 0a 09 2a 2f 0a |the bott|om...*/.|
|00003c40| 09 69 66 20 28 65 64 69 | 72 3d 67 6f 74 5f 76 69 |.if (edi|r=got_vi|
|00003c50| 28 2a 2d 2d 61 72 67 73 | 29 29 7b 0a 09 09 72 65 |(*--args|)){...re|
|00003c60| 61 64 5f 68 69 73 74 28 | 65 64 69 72 29 3b 0a 09 |ad_hist(|edir);..|
|00003c70| 09 63 6f 75 6e 74 3d 73 | 70 6c 69 74 5f 68 69 73 |.count=s|plit_his|
|00003c80| 74 28 29 3b 0a 09 09 66 | 6f 72 20 28 69 3d 30 3b |t();...f|or (i=0;|
|00003c90| 69 3c 63 6f 75 6e 74 3b | 69 2b 2b 29 7b 0a 09 09 |i<count;|i++){...|
|00003ca0| 09 69 66 20 28 21 73 74 | 72 63 6d 70 28 68 69 73 |.if (!st|rcmp(his|
|00003cb0| 74 5b 69 5d 2c 61 72 67 | 29 29 7b 0a 09 09 09 09 |t[i],arg|)){.....|
|00003cc0| 72 65 63 6f 6e 73 74 72 | 75 63 74 28 69 2c 63 6f |reconstr|uct(i,co|
|00003cd0| 75 6e 74 2c 65 64 69 72 | 29 3b 0a 09 09 09 09 72 |unt,edir|);.....r|
|00003ce0| 65 74 75 72 6e 3b 0a 09 | 09 09 7d 0a 09 09 7d 0a |eturn;..|..}...}.|
|00003cf0| 09 09 2f 2a 20 0a 09 09 | 20 20 20 72 65 62 75 69 |../* ...| rebui|
|00003d00| 6c 64 2c 20 69 6e 63 6c | 75 64 69 6e 67 20 65 76 |ld, incl|uding ev|
|00003d10| 65 72 79 74 68 69 6e 67 | 20 62 75 74 20 74 68 65 |erything| but the|
|00003d20| 20 63 6f 75 6e 74 68 20 | 6c 61 73 74 20 28 69 2e | counth |last (i.|
|00003d30| 65 2e 20 6d 61 6b 65 0a | 09 09 20 20 20 61 20 6e |e. make.|.. a n|
|00003d40| 65 77 20 68 69 73 74 6f | 72 79 20 62 79 20 6f 6d |ew histo|ry by om|
|00003d50| 69 74 74 69 6e 67 20 74 | 68 65 20 6f 6c 64 65 73 |itting t|he oldes|
|00003d60| 74 20 66 69 6c 65 20 69 | 6e 20 74 68 65 20 63 75 |t file i|n the cu|
|00003d70| 72 72 65 6e 74 20 6f 6e | 65 20 61 6e 64 0a 09 09 |rrent on|e and...|
|00003d80| 20 20 20 70 75 74 74 69 | 6e 67 20 27 61 72 67 27 | putti|ng 'arg'|
|00003d90| 20 6f 6e 20 74 68 65 20 | 65 6e 64 2e 0a 09 09 2a | on the |end....*|
|00003da0| 2f 0a 09 09 72 65 63 6f | 6e 73 74 72 75 63 74 28 |/...reco|nstruct(|
|00003db0| 48 49 53 54 5f 4c 49 4e | 45 53 2c 63 6f 75 6e 74 |HIST_LIN|ES,count|
|00003dc0| 2c 65 64 69 72 29 3b 0a | 09 7d 0a 09 65 6c 73 65 |,edir);.|.}..else|
|00003dd0| 7b 0a 09 09 2f 2a 20 74 | 68 65 72 65 20 77 61 73 |{.../* t|here was|
|00003de0| 20 6e 6f 20 68 69 73 74 | 6f 72 79 20 66 69 6c 65 | no hist|ory file|
|00003df0| 20 73 6f 20 74 72 79 20 | 74 6f 20 67 69 76 65 20 | so try |to give |
|00003e00| 74 68 65 6d 20 6f 6e 65 | 20 66 6f 72 20 6e 65 78 |them one| for nex|
|00003e10| 74 20 74 69 6d 65 20 2a | 2f 0a 09 09 6e 65 77 5f |t time *|/...new_|
|00003e20| 76 69 28 2a 61 72 67 73 | 29 3b 0a 09 7d 0a 7d 0a |vi(*args|);..}.}.|
|00003e30| 0a 63 68 61 72 20 2a 0a | 67 6f 74 5f 76 69 28 66 |.char *.|got_vi(f|
|00003e40| 69 6c 65 6e 61 6d 65 29 | 0a 63 68 61 72 20 2a 66 |ilename)|.char *f|
|00003e50| 69 6c 65 6e 61 6d 65 3b | 0a 7b 0a 09 2f 2a 20 69 |ilename;|.{../* i|
|00003e60| 6e 64 69 63 61 74 65 20 | 69 66 20 74 68 65 72 65 |ndicate |if there|
|00003e70| 20 69 73 20 61 20 68 69 | 73 74 6f 72 79 20 66 69 | is a hi|story fi|
|00003e80| 6c 65 20 74 68 61 74 20 | 74 68 65 79 20 6f 77 6e |le that |they own|
|00003e90| 20 6f 72 20 6f 74 68 65 | 72 77 69 73 65 20 2a 2f | or othe|rwise */|
|00003ea0| 0a 09 73 74 72 75 63 74 | 20 73 74 61 74 20 62 75 |..struct| stat bu|
|00003eb0| 66 3b 0a 09 73 74 61 74 | 69 63 20 63 68 61 72 20 |f;..stat|ic char |
|00003ec0| 64 69 72 62 75 66 66 65 | 72 5b 48 46 49 4c 45 4c |dirbuffe|r[HFILEL|
|00003ed0| 45 4e 5d 3b 0a 09 63 68 | 61 72 20 2a 66 70 74 72 |EN];..ch|ar *fptr|
|00003ee0| 3b 0a 0a 09 73 74 72 63 | 70 79 28 64 69 72 62 75 |;...strc|py(dirbu|
|00003ef0| 66 66 65 72 2c 20 66 69 | 6c 65 6e 61 6d 65 29 3b |ffer, fi|lename);|
|00003f00| 0a 09 69 66 20 28 28 66 | 70 74 72 3d 72 69 6e 64 |..if ((f|ptr=rind|
|00003f10| 65 78 28 64 69 72 62 75 | 66 66 65 72 2c 27 2f 27 |ex(dirbu|ffer,'/'|
|00003f20| 29 29 3d 3d 30 29 20 7b | 0a 09 09 66 6f 72 20 28 |))==0) {|...for (|
|00003f30| 66 70 74 72 3d 64 69 72 | 62 75 66 66 65 72 3b 20 |fptr=dir|buffer; |
|00003f40| 2a 66 70 74 72 3b 20 66 | 70 74 72 2b 2b 29 3b 0a |*fptr; f|ptr++);.|
|00003f50| 09 09 2a 66 70 74 72 3d | 27 2f 27 3b 0a 09 7d 0a |..*fptr=|'/';..}.|
|00003f60| 09 66 70 74 72 2b 2b 3b | 0a 09 73 74 72 63 70 79 |.fptr++;|..strcpy|
|00003f70| 28 66 70 74 72 2c 48 49 | 53 54 29 3b 0a 09 69 66 |(fptr,HI|ST);..if|
|00003f80| 20 28 73 74 61 74 28 64 | 69 72 62 75 66 66 65 72 | (stat(d|irbuffer|
|00003f90| 2c 26 62 75 66 29 3d 3d | 2d 31 20 7c 7c 20 67 65 |,&buf)==|-1 || ge|
|00003fa0| 74 75 69 64 28 29 21 3d | 62 75 66 2e 73 74 5f 75 |tuid()!=|buf.st_u|
|00003fb0| 69 64 29 7b 0a 09 09 72 | 65 74 75 72 6e 28 28 63 |id){...r|eturn((c|
|00003fc0| 68 61 72 20 2a 29 30 29 | 3b 0a 09 7d 0a 09 65 6c |har *)0)|;..}..el|
|00003fd0| 73 65 7b 0a 09 09 2a 2d | 2d 66 70 74 72 20 3d 20 |se{...*-|-fptr = |
|00003fe0| 27 5c 30 27 3b 0a 09 09 | 72 65 74 75 72 6e 28 64 |'\0';...|return(d|
|00003ff0| 69 72 62 75 66 66 65 72 | 29 3b 0a 09 7d 0a 7d 0a |irbuffer|);..}.}.|
|00004000| 0a 6e 65 77 5f 76 69 28 | 66 69 6c 65 6e 61 6d 65 |.new_vi(|filename|
|00004010| 29 0a 7b 0a 09 2f 2a 20 | 61 74 74 65 6d 70 74 20 |).{../* |attempt |
|00004020| 74 6f 20 6d 61 6b 65 20 | 61 20 6e 65 77 20 68 69 |to make |a new hi|
|00004030| 73 74 6f 72 79 20 66 69 | 6c 65 20 2d 20 73 65 76 |story fi|le - sev|
|00004040| 65 72 61 6c 20 74 68 69 | 6e 67 73 20 63 6f 75 6c |eral thi|ngs coul|
|00004050| 64 20 67 6f 20 77 72 6f | 6e 67 20 2a 2f 0a 09 46 |d go wro|ng */..F|
|00004060| 49 4c 45 20 2a 76 68 2c | 2a 66 6f 70 65 6e 28 29 |ILE *vh,|*fopen()|
|00004070| 2c 2a 66 63 6c 6f 73 65 | 28 29 3b 0a 09 73 74 72 |,*fclose|();..str|
|00004080| 75 63 74 20 73 74 61 74 | 20 62 75 66 3b 0a 09 63 |uct stat| buf;..c|
|00004090| 68 61 72 20 64 69 72 62 | 75 66 66 65 72 5b 48 46 |har dirb|uffer[HF|
|000040a0| 49 4c 45 4c 45 4e 5d 3b | 0a 09 63 68 61 72 20 2a |ILELEN];|..char *|
|000040b0| 66 70 74 72 3b 0a 0a 09 | 2f 2a 20 67 72 61 62 20 |fptr;...|/* grab |
|000040c0| 64 69 72 65 63 74 6f 72 | 79 20 6f 66 20 66 69 6c |director|y of fil|
|000040d0| 65 6e 61 6d 65 20 2a 2f | 0a 09 73 74 72 63 70 79 |ename */|..strcpy|
|000040e0| 28 64 69 72 62 75 66 66 | 65 72 2c 20 66 69 6c 65 |(dirbuff|er, file|
|000040f0| 6e 61 6d 65 29 3b 0a 09 | 69 66 20 28 66 70 74 72 |name);..|if (fptr|
|00004100| 3d 72 69 6e 64 65 78 28 | 64 69 72 62 75 66 66 65 |=rindex(|dirbuffe|
|00004110| 72 2c 27 2f 27 29 29 20 | 2a 2b 2b 66 70 74 72 20 |r,'/')) |*++fptr |
|00004120| 3d 20 27 5c 30 27 3b 0a | 09 65 6c 73 65 20 7b 0a |= '\0';.|.else {.|
|00004130| 09 09 73 74 72 63 70 79 | 28 64 69 72 62 75 66 66 |..strcpy|(dirbuff|
|00004140| 65 72 2c 22 2e 2f 22 29 | 3b 0a 09 09 66 70 74 72 |er,"./")|;...fptr|
|00004150| 20 3d 20 26 64 69 72 62 | 75 66 66 65 72 5b 32 5d | = &dirb|uffer[2]|
|00004160| 3b 0a 09 7d 0a 0a 09 2f | 2a 20 69 66 20 79 6f 75 |;..}.../|* if you|
|00004170| 20 63 61 6e 27 74 20 72 | 65 61 64 20 74 68 65 20 | can't r|ead the |
|00004180| 63 75 72 72 65 6e 74 20 | 64 69 72 65 63 74 6f 72 |current |director|
|00004190| 79 2c 20 67 65 74 20 6f | 75 74 20 2a 2f 0a 09 69 |y, get o|ut */..i|
|000041a0| 66 20 28 73 74 61 74 28 | 64 69 72 62 75 66 66 65 |f (stat(|dirbuffe|
|000041b0| 72 2c 62 75 66 29 3d 3d | 2d 31 29 7b 0a 09 09 70 |r,buf)==|-1){...p|
|000041c0| 65 72 72 6f 72 28 22 73 | 74 61 74 22 29 3b 0a 09 |error("s|tat");..|
|000041d0| 09 65 78 69 74 28 31 29 | 3b 0a 09 7d 0a 0a 09 2f |.exit(1)|;..}.../|
|000041e0| 2a 20 69 66 20 79 6f 75 | 20 6f 77 6e 20 74 68 65 |* if you| own the|
|000041f0| 20 64 69 72 65 63 74 6f | 72 79 20 28 79 6f 75 20 | directo|ry (you |
|00004200| 63 61 6e 27 74 20 6e 6f | 72 6d 61 6c 6c 79 20 67 |can't no|rmally g|
|00004210| 65 74 20 61 20 68 69 73 | 74 6f 72 79 20 69 6e 20 |et a his|tory in |
|00004220| 2f 74 6d 70 29 20 2a 2f | 0a 09 69 66 20 28 67 65 |/tmp) */|..if (ge|
|00004230| 74 75 69 64 28 29 3d 3d | 62 75 66 2e 73 74 5f 75 |tuid()==|buf.st_u|
|00004240| 69 64 29 7b 0a 0a 09 09 | 2f 2a 20 69 66 20 77 65 |id){....|/* if we|
|00004250| 20 63 61 6e 27 74 20 6d | 61 6b 65 20 61 20 68 69 | can't m|ake a hi|
|00004260| 73 74 6f 72 79 2c 20 67 | 65 74 20 6f 75 74 20 2a |story, g|et out *|
|00004270| 2f 0a 09 09 73 74 72 63 | 61 74 28 64 69 72 62 75 |/...strc|at(dirbu|
|00004280| 66 66 65 72 2c 48 49 53 | 54 29 3b 0a 09 09 69 66 |ffer,HIS|T);...if|
|00004290| 20 28 28 76 68 3d 66 6f | 70 65 6e 28 64 69 72 62 | ((vh=fo|pen(dirb|
|000042a0| 75 66 66 65 72 2c 22 77 | 22 29 29 3d 3d 4e 55 4c |uffer,"w|"))==NUL|
|000042b0| 4c 29 7b 0a 09 09 09 70 | 65 72 72 6f 72 28 64 69 |L){....p|error(di|
|000042c0| 72 62 75 66 66 65 72 29 | 3b 0a 09 09 09 65 78 69 |rbuffer)|;....exi|
|000042d0| 74 28 31 29 3b 0a 09 09 | 7d 0a 0a 09 09 2f 2a 20 |t(1);...|}..../* |
|000042e0| 70 75 74 20 69 6e 20 74 | 68 65 20 27 61 72 67 27 |put in t|he 'arg'|
|000042f0| 20 74 68 61 74 20 77 65 | 20 77 69 6c 6c 20 62 65 | that we| will be|
|00004300| 20 76 69 27 69 6e 67 20 | 69 6e 20 61 20 73 65 63 | vi'ing |in a sec|
|00004310| 6f 6e 64 2c 0a 09 09 20 | 20 20 61 66 74 65 72 20 |ond,... | after |
|00004320| 65 78 74 72 61 63 74 69 | 6e 67 20 69 74 27 73 20 |extracti|ng it's |
|00004330| 74 61 69 6c 2e 20 2a 2f | 0a 09 09 69 66 20 28 66 |tail. */|...if (f|
|00004340| 70 74 72 3d 72 69 6e 64 | 65 78 28 61 72 67 2c 27 |ptr=rind|ex(arg,'|
|00004350| 2f 27 29 29 20 66 70 74 | 72 2b 2b 3b 0a 09 09 65 |/')) fpt|r++;...e|
|00004360| 6c 73 65 20 66 70 74 72 | 3d 61 72 67 3b 0a 09 09 |lse fptr|=arg;...|
|00004370| 66 70 72 69 6e 74 66 28 | 76 68 2c 22 25 73 5c 6e |fprintf(|vh,"%s\n|
|00004380| 22 2c 66 70 74 72 29 3b | 0a 0a 09 09 2f 2a 20 63 |",fptr);|..../* c|
|00004390| 6c 6f 73 65 20 74 68 65 | 20 68 69 73 74 6f 72 79 |lose the| history|
|000043a0| 20 2a 2f 0a 09 09 69 66 | 20 28 66 63 6c 6f 73 65 | */...if| (fclose|
|000043b0| 28 76 68 29 3d 3d 28 46 | 49 4c 45 20 2a 29 45 4f |(vh)==(F|ILE *)EO|
|000043c0| 46 29 7b 0a 09 09 09 66 | 70 72 69 6e 74 66 28 73 |F){....f|printf(s|
|000043d0| 74 64 65 72 72 2c 22 43 | 6f 75 6c 64 20 6e 6f 74 |tderr,"C|ould not|
|000043e0| 20 63 6c 6f 73 65 20 25 | 73 5c 6e 22 2c 64 69 72 | close %|s\n",dir|
|000043f0| 62 75 66 66 65 72 29 3b | 0a 09 09 09 65 78 69 74 |buffer);|....exit|
|00004400| 28 31 29 3b 0a 09 09 7d | 0a 0a 09 09 2f 2a 20 67 |(1);...}|..../* g|
|00004410| 69 76 65 20 74 68 65 20 | 68 69 73 74 6f 72 79 20 |ive the |history |
|00004420| 73 6f 6d 65 20 70 72 6f | 74 65 63 74 69 6f 6e 20 |some pro|tection |
|00004430| 2d 20 66 6f 72 20 74 68 | 6f 73 65 20 77 68 6f 20 |- for th|ose who |
|00004440| 77 61 6e 74 20 69 74 21 | 20 2a 2f 0a 09 09 69 66 |want it!| */...if|
|00004450| 20 28 63 68 6d 6f 64 28 | 64 69 72 62 75 66 66 65 | (chmod(|dirbuffe|
|00004460| 72 2c 49 52 45 41 44 7c | 49 57 52 49 54 45 29 3d |r,IREAD||IWRITE)=|
|00004470| 3d 2d 31 29 7b 0a 09 09 | 09 70 65 72 72 6f 72 28 |=-1){...|.perror(|
|00004480| 22 63 68 6d 6f 64 22 29 | 3b 0a 09 09 09 65 78 69 |"chmod")|;....exi|
|00004490| 74 28 31 29 3b 0a 09 09 | 7d 0a 09 7d 0a 7d 0a 0a |t(1);...|}..}.}..|
|000044a0| 63 6c 65 61 6e 5f 75 70 | 28 29 0a 7b 0a 09 2f 2a |clean_up|().{../*|
|000044b0| 20 6a 75 73 74 20 67 65 | 74 20 6f 75 74 20 61 66 | just ge|t out af|
|000044c0| 74 65 72 20 6d 61 6b 69 | 6e 67 20 73 75 72 65 20 |ter maki|ng sure |
|000044d0| 74 68 69 6e 67 73 20 61 | 72 65 20 74 69 64 79 20 |things a|re tidy |
|000044e0| 2a 2f 0a 09 66 70 72 69 | 6e 74 66 28 73 74 64 65 |*/..fpri|ntf(stde|
|000044f0| 72 72 2c 22 49 6e 74 65 | 72 72 75 70 74 2e 5c 6e |rr,"Inte|rrupt.\n|
|00004500| 22 29 3b 0a 09 75 6e 6c | 69 6e 6b 28 74 6d 70 5f |");..unl|ink(tmp_|
|00004510| 66 69 6c 65 29 3b 0a 09 | 75 6e 73 65 74 5f 74 65 |file);..|unset_te|
|00004520| 72 6d 28 29 3b 0a 09 65 | 78 69 74 28 31 29 3b 0a |rm();..e|xit(1);.|
|00004530| 7d 0a 0a 73 70 65 6c 6c | 5f 68 65 6c 70 28 29 0a |}..spell|_help().|
|00004540| 7b 0a 09 2f 2a 0a 09 20 | 20 20 75 6e 61 73 68 61 |{../*.. | unasha|
|00004550| 6d 65 64 6c 79 20 73 74 | 6f 6c 65 6e 20 28 61 6e |medly st|olen (an|
|00004560| 64 20 6d 6f 64 69 66 69 | 65 64 29 20 66 72 6f 6d |d modifi|ed) from|
|00004570| 20 22 54 68 65 20 55 4e | 49 58 20 50 72 6f 67 72 | "The UN|IX Progr|
|00004580| 61 6d 6d 69 6e 67 0a 09 | 20 20 20 45 6e 76 69 72 |amming..| Envir|
|00004590| 6f 6e 6d 65 6e 74 22 20 | 2d 20 4b 65 72 6e 69 67 |onment" |- Kernig|
|000045a0| 68 61 6e 20 61 6e 64 20 | 50 69 6b 65 0a 0a 09 20 |han and |Pike... |
|000045b0| 20 20 72 65 61 64 20 74 | 68 65 20 64 69 72 65 63 | read t|he direc|
|000045c0| 74 6f 72 79 20 61 6e 64 | 20 69 66 20 74 68 65 20 |tory and| if the |
|000045d0| 66 69 6c 65 20 74 68 65 | 79 20 77 61 6e 74 20 28 |file the|y want (|
|000045e0| 69 6e 20 27 61 72 67 27 | 29 20 64 6f 65 73 20 6e |in 'arg'|) does n|
|000045f0| 6f 74 0a 09 20 20 20 65 | 78 69 73 74 20 74 68 65 |ot.. e|xist the|
|00004600| 6e 20 73 65 65 20 69 66 | 20 74 68 65 72 65 20 69 |n see if| there i|
|00004610| 73 20 6f 6e 65 20 74 68 | 61 74 20 64 6f 65 73 20 |s one th|at does |
|00004620| 74 68 61 74 20 68 61 73 | 20 73 69 6d 69 6c 61 72 |that has| similar|
|00004630| 20 73 70 65 6c 6c 69 6e | 67 0a 09 20 20 20 74 6f | spellin|g.. to|
|00004640| 20 77 68 61 74 20 74 68 | 65 79 20 72 65 71 75 65 | what th|ey reque|
|00004650| 73 74 65 64 2e 20 6f 66 | 66 65 72 20 74 68 65 20 |sted. of|fer the |
|00004660| 63 68 61 6e 67 65 20 61 | 6e 64 20 68 61 6e 64 6c |change a|nd handl|
|00004670| 65 20 74 68 65 20 72 65 | 70 6c 79 2e 0a 09 2a 2f |e the re|ply...*/|
|00004680| 0a 0a 09 63 68 61 72 20 | 6e 65 77 5b 41 52 47 5f |...char |new[ARG_|
|00004690| 43 48 41 52 53 5d 3b 0a | 09 72 65 67 69 73 74 65 |CHARS];.|.registe|
|000046a0| 72 20 64 69 73 74 3d 33 | 3b 0a 09 72 65 67 69 73 |r dist=3|;..regis|
|000046b0| 74 65 72 20 6e 65 77 5f | 64 69 73 74 3b 0a 09 44 |ter new_|dist;..D|
|000046c0| 49 52 20 2a 64 70 2c 20 | 2a 6f 70 65 6e 64 69 72 |IR *dp, |*opendir|
|000046d0| 28 29 3b 0a 09 73 74 72 | 75 63 74 20 64 69 72 65 |();..str|uct dire|
|000046e0| 63 74 20 2a 72 65 61 64 | 64 69 72 28 29 3b 0a 09 |ct *read|dir();..|
|000046f0| 73 74 72 75 63 74 20 64 | 69 72 65 63 74 20 2a 65 |struct d|irect *e|
|00004700| 6e 74 72 79 3b 0a 09 72 | 65 67 69 73 74 65 72 20 |ntry;..r|egister |
|00004710| 6c 65 6e 3b 0a 09 73 74 | 72 75 63 74 20 73 74 61 |len;..st|ruct sta|
|00004720| 74 20 62 75 66 3b 0a 09 | 63 68 61 72 20 64 69 72 |t buf;..|char dir|
|00004730| 62 75 66 66 65 72 5b 48 | 46 49 4c 45 4c 45 4e 5d |buffer[H|FILELEN]|
|00004740| 3b 0a 09 63 68 61 72 20 | 2a 66 70 74 72 3b 0a 0a |;..char |*fptr;..|
|00004750| 09 2f 2a 20 69 66 20 74 | 68 65 20 66 69 6c 65 20 |./* if t|he file |
|00004760| 61 6c 72 65 61 64 79 20 | 65 78 69 73 74 73 20 6a |already |exists j|
|00004770| 75 73 74 20 72 65 74 75 | 72 6e 20 2d 20 74 68 65 |ust retu|rn - the|
|00004780| 79 20 64 6f 6e 27 74 20 | 6e 65 65 64 20 68 65 6c |y don't |need hel|
|00004790| 70 20 2a 2f 0a 09 69 66 | 20 28 73 74 61 74 28 61 |p */..if| (stat(a|
|000047a0| 72 67 2c 26 62 75 66 29 | 3d 3d 30 29 7b 0a 09 09 |rg,&buf)|==0){...|
|000047b0| 72 65 74 75 72 6e 3b 0a | 09 7d 0a 0a 09 2f 2a 20 |return;.|.}.../* |
|000047c0| 69 66 20 74 68 65 20 63 | 75 72 72 65 6e 74 20 64 |if the c|urrent d|
|000047d0| 69 72 65 63 74 6f 72 79 | 20 63 61 6e 27 74 20 62 |irectory| can't b|
|000047e0| 65 20 72 65 61 64 20 74 | 68 65 6e 20 72 65 74 75 |e read t|hen retu|
|000047f0| 72 6e 20 2a 2f 0a 09 73 | 74 72 63 70 79 28 64 69 |rn */..s|trcpy(di|
|00004800| 72 62 75 66 66 65 72 2c | 20 61 72 67 29 3b 0a 09 |rbuffer,| arg);..|
|00004810| 69 66 20 28 66 70 74 72 | 3d 72 69 6e 64 65 78 28 |if (fptr|=rindex(|
|00004820| 64 69 72 62 75 66 66 65 | 72 2c 27 2f 27 29 29 20 |dirbuffe|r,'/')) |
|00004830| 2a 66 70 74 72 2b 2b 3d | 27 5c 30 27 3b 0a 09 65 |*fptr++=|'\0';..e|
|00004840| 6c 73 65 20 7b 0a 09 09 | 73 74 72 63 70 79 28 64 |lse {...|strcpy(d|
|00004850| 69 72 62 75 66 66 65 72 | 2c 20 64 6f 74 73 74 72 |irbuffer|, dotstr|
|00004860| 69 6e 67 29 3b 0a 09 09 | 66 70 74 72 3d 61 72 67 |ing);...|fptr=arg|
|00004870| 3b 0a 09 7d 0a 09 69 66 | 20 28 28 64 70 3d 6f 70 |;..}..if| ((dp=op|
|00004880| 65 6e 64 69 72 28 64 69 | 72 62 75 66 66 65 72 29 |endir(di|rbuffer)|
|00004890| 29 3d 3d 4e 55 4c 4c 29 | 7b 0a 09 09 72 65 74 75 |)==NULL)|{...retu|
|000048a0| 72 6e 3b 0a 09 7d 0a 09 | 0a 09 2f 2a 20 67 65 74 |rn;..}..|../* get|
|000048b0| 20 74 68 65 20 6c 65 6e | 67 74 68 20 6f 66 20 77 | the len|gth of w|
|000048c0| 68 61 74 20 77 65 20 61 | 72 65 20 73 65 65 6b 69 |hat we a|re seeki|
|000048d0| 6e 67 20 74 6f 20 63 75 | 74 20 64 6f 77 6e 20 6f |ng to cu|t down o|
|000048e0| 6e 20 73 74 72 63 6d 70 | 69 6e 67 20 74 69 6d 65 |n strcmp|ing time|
|000048f0| 20 2a 2f 0a 09 6c 65 6e | 3d 73 74 72 6c 65 6e 28 | */..len|=strlen(|
|00004900| 66 70 74 72 29 3b 0a 0a | 09 66 6f 72 20 28 65 6e |fptr);..|.for (en|
|00004910| 74 72 79 3d 72 65 61 64 | 64 69 72 28 64 70 29 3b |try=read|dir(dp);|
|00004920| 65 6e 74 72 79 21 3d 4e | 55 4c 4c 3b 65 6e 74 72 |entry!=N|ULL;entr|
|00004930| 79 3d 72 65 61 64 64 69 | 72 28 64 70 29 29 7b 0a |y=readdi|r(dp)){.|
|00004940| 0a 09 09 2f 2a 20 69 66 | 20 74 68 69 73 20 65 6e |.../* if| this en|
|00004950| 74 72 79 20 68 61 73 20 | 6c 65 6e 67 74 68 20 3d |try has |length =|
|00004960| 20 73 6f 75 67 68 74 20 | 6c 65 6e 67 74 68 20 2b | sought |length +|
|00004970| 2f 2d 20 31 20 74 68 65 | 6e 20 69 74 20 6d 61 79 |/- 1 the|n it may|
|00004980| 20 62 65 20 6f 6b 20 2a | 2f 0a 09 09 69 66 20 28 | be ok *|/...if (|
|00004990| 65 6e 74 72 79 2d 3e 64 | 5f 69 6e 6f 26 26 65 6e |entry->d|_ino&&en|
|000049a0| 74 72 79 2d 3e 64 5f 6e | 61 6d 6c 65 6e 3e 3d 6c |try->d_n|amlen>=l|
|000049b0| 65 6e 2d 31 26 26 65 6e | 74 72 79 2d 3e 64 5f 6e |en-1&&en|try->d_n|
|000049c0| 61 6d 6c 65 6e 3c 3d 6c | 65 6e 2b 31 29 7b 0a 0a |amlen<=l|en+1){..|
|000049d0| 09 09 09 2f 2a 20 67 65 | 74 20 74 68 65 20 27 64 |.../* ge|t the 'd|
|000049e0| 69 73 74 61 6e 63 65 27 | 20 62 65 74 77 65 65 6e |istance'| between|
|000049f0| 20 77 68 61 74 20 77 65 | 20 77 61 6e 74 20 61 6e | what we| want an|
|00004a00| 64 20 74 68 69 73 20 66 | 69 6c 65 20 6e 61 6d 65 |d this f|ile name|
|00004a10| 20 2a 2f 0a 09 09 09 6e | 65 77 5f 64 69 73 74 3d | */....n|ew_dist=|
|00004a20| 73 70 5f 64 69 73 74 28 | 65 6e 74 72 79 2d 3e 64 |sp_dist(|entry->d|
|00004a30| 5f 6e 61 6d 65 2c 66 70 | 74 72 29 3b 0a 0a 09 09 |_name,fp|tr);....|
|00004a40| 09 2f 2a 20 69 66 20 74 | 68 69 73 20 6e 61 6d 65 |./* if t|his name|
|00004a50| 20 69 73 20 63 6c 6f 73 | 65 20 65 6e 6f 75 67 68 | is clos|e enough|
|00004a60| 20 61 6e 64 20 62 65 74 | 74 65 72 20 74 68 61 6e | and bet|ter than|
|00004a70| 20 6f 75 72 20 63 75 72 | 72 65 6e 74 20 62 65 73 | our cur|rent bes|
|00004a80| 74 20 2a 2f 0a 09 09 09 | 69 66 20 28 6e 65 77 5f |t */....|if (new_|
|00004a90| 64 69 73 74 3c 3d 64 69 | 73 74 26 26 6e 65 77 5f |dist<=di|st&&new_|
|00004aa0| 64 69 73 74 21 3d 33 29 | 7b 0a 0a 09 09 09 09 69 |dist!=3)|{......i|
|00004ab0| 66 20 28 21 6e 65 77 5f | 64 69 73 74 29 7b 0a 09 |f (!new_|dist){..|
|00004ac0| 09 09 09 09 2f 2a 20 69 | 66 20 74 68 65 20 64 69 |..../* i|f the di|
|00004ad0| 73 74 20 69 73 20 30 20 | 74 68 65 6e 20 74 68 65 |st is 0 |then the|
|00004ae0| 79 20 61 72 65 20 69 64 | 65 6e 74 69 63 61 6c 20 |y are id|entical |
|00004af0| 2a 2f 0a 09 09 09 09 09 | 63 6c 6f 73 65 64 69 72 |*/......|closedir|
|00004b00| 28 64 70 29 3b 0a 09 09 | 09 09 09 72 65 74 75 72 |(dp);...|...retur|
|00004b10| 6e 3b 0a 09 09 09 09 7d | 0a 09 09 09 09 2f 2a 20 |n;.....}|...../* |
|00004b20| 72 65 6d 65 6d 62 65 72 | 20 74 68 65 20 6e 65 77 |remember| the new|
|00004b30| 20 6e 61 6d 65 20 61 6e | 64 20 64 69 73 74 61 6e | name an|d distan|
|00004b40| 63 65 20 2a 2f 0a 09 09 | 09 09 73 74 72 63 70 79 |ce */...|..strcpy|
|00004b50| 28 6e 65 77 2c 65 6e 74 | 72 79 2d 3e 64 5f 6e 61 |(new,ent|ry->d_na|
|00004b60| 6d 65 29 3b 0a 09 09 09 | 09 64 69 73 74 3d 6e 65 |me);....|.dist=ne|
|00004b70| 77 5f 64 69 73 74 3b 0a | 09 09 09 7d 0a 09 09 7d |w_dist;.|...}...}|
|00004b80| 0a 09 7d 0a 0a 09 2f 2a | 20 63 6c 6f 73 65 20 75 |..}.../*| close u|
|00004b90| 70 2e 20 69 66 20 77 65 | 20 67 6f 74 20 6e 6f 20 |p. if we| got no |
|00004ba0| 73 75 69 74 61 62 6c 65 | 20 72 65 73 75 6c 74 20 |suitable| result |
|00004bb0| 74 68 65 6e 20 73 69 6d | 70 6c 79 20 72 65 74 75 |then sim|ply retu|
|00004bc0| 72 6e 20 2a 2f 0a 09 63 | 6c 6f 73 65 64 69 72 28 |rn */..c|losedir(|
|00004bd0| 64 70 29 3b 0a 09 69 66 | 20 28 64 69 73 74 3d 3d |dp);..if| (dist==|
|00004be0| 33 29 7b 0a 09 09 72 65 | 74 75 72 6e 3b 0a 09 7d |3){...re|turn;..}|
|00004bf0| 0a 0a 09 2f 2a 20 6f 66 | 66 65 72 20 74 68 65 6d |.../* of|fer them|
|00004c00| 20 22 6e 65 77 22 20 2a | 2f 0a 09 73 65 74 5f 74 | "new" *|/..set_t|
|00004c10| 65 72 6d 28 29 3b 0a 09 | 66 70 72 69 6e 74 66 28 |erm();..|fprintf(|
|00004c20| 73 74 64 65 72 72 2c 22 | 63 6f 72 72 65 63 74 20 |stderr,"|correct |
|00004c30| 74 6f 20 25 73 20 5b 79 | 5d 3f 20 22 2c 6e 65 77 |to %s [y|]? ",new|
|00004c40| 29 3b 0a 0a 09 2f 2a 20 | 70 72 6f 63 65 73 73 20 |);.../* |process |
|00004c50| 74 68 65 20 72 65 70 6c | 79 20 2a 2f 0a 09 73 77 |the repl|y */..sw|
|00004c60| 69 74 63 68 20 28 67 65 | 74 63 28 73 74 64 69 6e |itch (ge|tc(stdin|
|00004c70| 29 29 7b 0a 09 09 63 61 | 73 65 20 27 4e 27 3a 0a |)){...ca|se 'N':.|
|00004c80| 09 09 63 61 73 65 20 27 | 6e 27 3a 0a 09 09 09 66 |..case '|n':....f|
|00004c90| 70 72 69 6e 74 66 28 73 | 74 64 65 72 72 2c 22 6e |printf(s|tderr,"n|
|00004ca0| 6f 5c 6e 22 29 3b 0a 09 | 09 09 62 72 65 61 6b 3b |o\n");..|..break;|
|00004cb0| 0a 09 09 63 61 73 65 20 | 27 71 27 3a 0a 09 09 63 |...case |'q':...c|
|00004cc0| 61 73 65 20 27 51 27 3a | 0a 09 09 09 66 70 72 69 |ase 'Q':|....fpri|
|00004cd0| 6e 74 66 28 73 74 64 65 | 72 72 2c 22 71 75 69 74 |ntf(stde|rr,"quit|
|00004ce0| 5c 6e 22 29 3b 0a 09 09 | 09 75 6e 73 65 74 5f 74 |\n");...|.unset_t|
|00004cf0| 65 72 6d 28 29 3b 0a 09 | 09 09 65 78 69 74 28 30 |erm();..|..exit(0|
|00004d00| 29 3b 0a 09 09 09 62 72 | 65 61 6b 3b 0a 09 09 64 |);....br|eak;...d|
|00004d10| 65 66 61 75 6c 74 20 3a | 0a 09 09 09 66 70 72 69 |efault :|....fpri|
|00004d20| 6e 74 66 28 73 74 64 65 | 72 72 2c 22 79 65 73 5c |ntf(stde|rr,"yes\|
|00004d30| 6e 22 29 3b 0a 09 09 09 | 69 66 20 28 66 70 74 72 |n");....|if (fptr|
|00004d40| 3d 3d 61 72 67 29 0a 09 | 09 09 09 73 74 72 63 70 |==arg)..|...strcp|
|00004d50| 79 28 61 72 67 2c 6e 65 | 77 29 3b 0a 09 09 09 65 |y(arg,ne|w);....e|
|00004d60| 6c 73 65 20 73 70 72 69 | 6e 74 66 28 61 72 67 2c |lse spri|ntf(arg,|
|00004d70| 22 25 73 2f 25 73 22 2c | 20 64 69 72 62 75 66 66 |"%s/%s",| dirbuff|
|00004d80| 65 72 2c 20 6e 65 77 29 | 3b 0a 09 7d 0a 09 75 6e |er, new)|;..}..un|
|00004d90| 73 65 74 5f 74 65 72 6d | 28 29 3b 0a 7d 0a 0a 73 |set_term|();.}..s|
|00004da0| 70 5f 64 69 73 74 28 73 | 2c 74 29 0a 63 68 61 72 |p_dist(s|,t).char|
|00004db0| 20 2a 73 3b 0a 63 68 61 | 72 20 2a 74 3b 0a 7b 0a | *s;.cha|r *t;.{.|
|00004dc0| 09 2f 2a 20 0a 09 20 20 | 20 73 74 6f 6c 65 6e 20 |./* .. | stolen |
|00004dd0| 66 72 6f 6d 20 74 68 65 | 20 73 61 6d 65 20 70 6c |from the| same pl|
|00004de0| 61 63 65 20 61 73 20 73 | 70 65 6c 6c 5f 68 65 6c |ace as s|pell_hel|
|00004df0| 70 28 29 20 61 62 6f 76 | 65 2e 0a 0a 09 20 20 20 |p() abov|e.... |
|00004e00| 77 6f 72 6b 20 6f 75 74 | 20 74 68 65 20 64 69 73 |work out| the dis|
|00004e10| 74 61 6e 63 65 20 62 65 | 74 77 65 65 6e 20 74 68 |tance be|tween th|
|00004e20| 65 20 73 74 72 69 6e 67 | 73 20 27 73 27 20 61 6e |e string|s 's' an|
|00004e30| 64 20 27 74 27 20 61 63 | 63 6f 72 64 69 6e 67 0a |d 't' ac|cording.|
|00004e40| 09 20 20 20 74 6f 20 74 | 68 65 20 72 6f 75 67 68 |. to t|he rough|
|00004e50| 20 6d 65 74 72 69 63 20 | 74 68 61 74 0a 09 20 20 | metric |that.. |
|00004e60| 20 0a 09 20 20 20 69 64 | 65 6e 74 69 63 61 6c 20 | .. id|entical |
|00004e70| 3d 20 30 0a 09 20 20 20 | 69 6e 74 65 72 63 68 61 |= 0.. |intercha|
|00004e80| 6e 67 65 64 20 63 68 61 | 72 61 63 74 65 72 73 20 |nged cha|racters |
|00004e90| 3d 20 31 0a 09 20 20 20 | 77 72 6f 6e 67 20 63 68 |= 1.. |wrong ch|
|00004ea0| 61 72 61 63 74 65 72 2f | 65 78 74 72 61 20 63 68 |aracter/|extra ch|
|00004eb0| 61 72 61 63 74 65 72 2f | 6d 69 73 73 69 6e 67 20 |aracter/|missing |
|00004ec0| 63 68 61 72 61 63 74 65 | 72 20 3d 20 32 0a 09 20 |characte|r = 2.. |
|00004ed0| 20 20 66 6f 72 67 65 74 | 20 69 74 20 3d 20 33 0a | forget| it = 3.|
|00004ee0| 09 2a 2f 0a 0a 09 77 68 | 69 6c 65 20 28 2a 73 2b |.*/...wh|ile (*s+|
|00004ef0| 2b 3d 3d 2a 74 29 7b 0a | 09 09 69 66 20 28 2a 74 |+==*t){.|..if (*t|
|00004f00| 2b 2b 3d 3d 27 5c 30 27 | 29 7b 0a 09 09 09 2f 2a |++=='\0'|){..../*|
|00004f10| 20 69 64 65 6e 74 69 63 | 61 6c 20 2a 2f 0a 09 09 | identic|al */...|
|00004f20| 09 72 65 74 75 72 6e 28 | 30 29 3b 0a 09 09 7d 0a |.return(|0);...}.|
|00004f30| 09 7d 0a 0a 09 69 66 20 | 28 2a 2d 2d 73 29 7b 0a |.}...if |(*--s){.|
|00004f40| 09 09 69 66 20 28 2a 74 | 29 7b 0a 09 09 09 69 66 |..if (*t|){....if|
|00004f50| 20 28 73 5b 31 5d 26 26 | 74 5b 31 5d 26 26 2a 73 | (s[1]&&|t[1]&&*s|
|00004f60| 3d 3d 74 5b 31 5d 26 26 | 2a 74 3d 3d 73 5b 31 5d |==t[1]&&|*t==s[1]|
|00004f70| 26 26 21 73 74 72 63 6d | 70 28 73 2b 32 2c 74 2b |&&!strcm|p(s+2,t+|
|00004f80| 32 29 29 7b 0a 09 09 09 | 09 2f 2a 20 69 6e 74 65 |2)){....|./* inte|
|00004f90| 72 63 68 61 6e 67 65 64 | 20 63 68 61 72 73 20 2a |rchanged| chars *|
|00004fa0| 2f 0a 09 09 09 09 72 65 | 74 75 72 6e 28 31 29 3b |/.....re|turn(1);|
|00004fb0| 0a 09 09 09 7d 0a 09 09 | 09 69 66 20 28 21 73 74 |....}...|.if (!st|
|00004fc0| 72 63 6d 70 28 73 2b 31 | 2c 74 2b 31 29 29 7b 0a |rcmp(s+1|,t+1)){.|
|00004fd0| 09 09 09 09 2f 2a 20 77 | 72 6f 6e 67 20 63 68 61 |..../* w|rong cha|
|00004fe0| 72 20 2a 2f 0a 09 09 09 | 09 72 65 74 75 72 6e 28 |r */....|.return(|
|00004ff0| 32 29 3b 0a 09 09 09 7d | 0a 09 09 7d 0a 09 09 69 |2);....}|...}...i|
|00005000| 66 20 28 21 73 74 72 63 | 6d 70 28 73 2b 31 2c 74 |f (!strc|mp(s+1,t|
|00005010| 29 29 7b 0a 09 09 09 2f | 2a 20 65 78 74 72 61 20 |)){..../|* extra |
|00005020| 63 68 61 72 20 69 6e 20 | 27 74 27 20 2a 2f 0a 09 |char in |'t' */..|
|00005030| 09 09 72 65 74 75 72 6e | 28 32 29 3b 0a 09 09 7d |..return|(2);...}|
|00005040| 0a 09 7d 0a 09 69 66 20 | 28 21 73 74 72 63 6d 70 |..}..if |(!strcmp|
|00005050| 28 73 2c 74 2b 31 29 29 | 7b 0a 09 09 2f 2a 20 65 |(s,t+1))|{.../* e|
|00005060| 78 74 72 61 20 63 68 61 | 72 20 69 6e 20 27 73 27 |xtra cha|r in 's'|
|00005070| 20 2a 2f 0a 09 09 72 65 | 74 75 72 6e 28 32 29 3b | */...re|turn(2);|
|00005080| 0a 09 7d 0a 0a 09 2f 2a | 20 66 6f 72 67 65 74 20 |..}.../*| forget |
|00005090| 69 74 20 2a 2f 0a 09 72 | 65 74 75 72 6e 28 33 29 |it */..r|eturn(3)|
|000050a0| 3b 0a 7d 0a 53 48 41 52 | 5f 45 4f 46 0a 63 68 6d |;.}.SHAR|_EOF.chm|
|000050b0| 6f 64 20 2b 78 20 27 65 | 2e 63 27 0a 66 69 0a 65 |od +x 'e|.c'.fi.e|
|000050c0| 78 69 74 20 30 0a 23 09 | 45 6e 64 20 6f 66 20 73 |xit 0.#.|End of s|
|000050d0| 68 65 6c 6c 20 61 72 63 | 68 69 76 65 0a 2d 2d 20 |hell arc|hive.-- |
|000050e0| 0a 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |.-------|--------|
|000050f0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00005100| 2d 2d 2d 0a 7c 20 53 69 | 6d 6f 6e 20 42 72 6f 77 |---.| Si|mon Brow|
|00005110| 6e 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |n | |
|00005120| 20 20 20 20 20 7c 20 55 | 55 43 50 3a 20 20 73 65 | | U|UCP: se|
|00005130| 69 73 6d 6f 21 6d 63 76 | 61 78 21 75 6b 63 21 7b |ismo!mcv|ax!ukc!{|
|00005140| 6c 66 63 73 2c 69 74 73 | 36 33 62 7d 21 73 69 6d |lfcs,its|63b}!sim|
|00005150| 6f 6e 0a 7c 20 44 65 70 | 61 72 74 6d 65 6e 74 20 |on.| Dep|artment |
|00005160| 6f 66 20 43 6f 6d 70 75 | 74 65 72 20 53 63 69 65 |of Compu|ter Scie|
|00005170| 6e 63 65 20 7c 20 4a 41 | 4e 45 54 3a 20 73 69 6d |nce | JA|NET: sim|
|00005180| 6f 6e 40 75 6b 2e 61 63 | 2e 65 64 2e 7b 6c 66 63 |on@uk.ac|.ed.{lfc|
|00005190| 73 2c 69 74 73 36 33 62 | 7d 0a 7c 20 55 6e 69 76 |s,its63b|}.| Univ|
|000051a0| 65 72 73 69 74 79 20 6f | 66 20 45 64 69 6e 62 75 |ersity o|f Edinbu|
|000051b0| 72 67 68 2c 20 20 20 20 | 20 20 20 7c 20 41 52 50 |rgh, | | ARP|
|000051c0| 41 3a 20 20 73 69 6d 6f | 6e 25 6c 66 63 73 2e 65 |A: simo|n%lfcs.e|
|000051d0| 64 2e 61 63 2e 75 6b 40 | 63 73 2e 75 63 6c 2e 61 |d.ac.uk@|cs.ucl.a|
|000051e0| 63 2e 75 6b 0a 7c 20 53 | 63 6f 74 6c 61 6e 64 2c |c.uk.| S|cotland,|
|000051f0| 20 55 4b 2e 20 20 20 20 | 20 20 20 20 20 20 20 20 | UK. | |
|00005200| 20 20 20 20 20 20 7c 20 | 20 20 20 20 6f 72 20 73 | | | or s|
|00005210| 69 6d 6f 6e 25 69 74 73 | 36 33 62 2e 65 64 2e 61 |imon%its|63b.ed.a|
|00005220| 63 2e 75 6b 40 63 73 2e | 75 63 6c 2e 61 63 2e 75 |c.uk@cs.|ucl.ac.u|
|00005230| 6b 0a 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |k.------|--------|
|00005240| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00005250| 2d 2d 2d 2d 20 20 20 20 | 20 6f 72 20 73 69 6d 6f |---- | or simo|
|00005260| 6e 25 63 73 74 76 61 78 | 2e 65 64 2e 61 63 2e 75 |n%cstvax|.ed.ac.u|
|00005270| 6b 40 63 73 2e 75 63 6c | 2e 61 63 2e 75 6b 0a 20 |k@cs.ucl|.ac.uk. |
|00005280| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00005290| 20 20 20 20 20 22 4c 69 | 66 65 27 73 20 6c 69 6b | "Li|fe's lik|
|000052a0| 65 20 74 68 61 74 2c 20 | 79 6f 75 20 6b 6e 6f 77 |e that, |you know|
|000052b0| 22 0a | |". | |
+--------+-------------------------+-------------------------+--------+--------+