home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume7 / patch2 / part03 < prev    next >
Text File  |  1986-11-30  |  15KB  |  537 lines

  1. Subject:  v07i040:  Release 2.0 of patch, Part03/03
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: sdcrdcf!lwall (Larry Wall)
  6. Mod.sources: Volume 7, Issue 40
  7. Archive-name: patch2/Part03
  8.  
  9. Here is the official 2.0 release of patch.  It supersedes the 1.5 beta
  10. version posted to net.sources, and the version that comes with 4.3bsd.
  11.  
  12. Larry Wall
  13. sdcrdcf!lwall
  14.  
  15. --------------------------CUT HERE---------------------------
  16. #! /bin/sh
  17.  
  18. # Make a new directory for the patch sources, cd to it, and run kits 1 thru 3 
  19. # through sh.  When all 3 kits have been run, read README.
  20.  
  21. echo "This is patch kit 3 (of 3).  If kit 3 is complete, the line"
  22. echo '"'"End of kit 3 (of 3)"'" will echo at the end.'
  23. echo ""
  24. export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
  25. echo Extracting common.h
  26. sed >common.h <<'!STUFFY!FUNK!' -e 's/X//'
  27. X/* $Header: common.h,v 2.0 86/09/17 15:36:39 lwall Exp $
  28. X *
  29. X * $Log:    common.h,v $
  30. X * Revision 2.0  86/09/17  15:36:39  lwall
  31. X * Baseline for netwide release.
  32. X * 
  33. X */
  34. X
  35. X#define DEBUGGING
  36. X
  37. X#include "config.h"
  38. X
  39. X/* shut lint up about the following when return value ignored */
  40. X
  41. X#define Signal (void)signal
  42. X#define Unlink (void)unlink
  43. X#define Lseek (void)lseek
  44. X#define Fseek (void)fseek
  45. X#define Fstat (void)fstat
  46. X#define Pclose (void)pclose
  47. X#define Close (void)close
  48. X#define Fclose (void)fclose
  49. X#define Fflush (void)fflush
  50. X#define Sprintf (void)sprintf
  51. X#define Mktemp (void)mktemp
  52. X#define Strcpy (void)strcpy
  53. X#define Strcat (void)strcat
  54. X
  55. X#include <stdio.h>
  56. X#include <assert.h>
  57. X#include <sys/types.h>
  58. X#include <sys/stat.h>
  59. X#include <ctype.h>
  60. X#include <signal.h>
  61. X
  62. X/* constants */
  63. X
  64. X#define TRUE (1)
  65. X#define FALSE (0)
  66. X
  67. X#define MAXHUNKSIZE 100000        /* is this enough lines? */
  68. X#define INITHUNKMAX 125            /* initial dynamic allocation size */
  69. X#define MAXLINELEN 1024
  70. X#define BUFFERSIZE 1024
  71. X#define ORIGEXT ".orig"
  72. X#define SCCSPREFIX "s."
  73. X#define GET "get -e %s"
  74. X#define RCSSUFFIX ",v"
  75. X#define CHECKOUT "co -l %s"
  76. X
  77. X/* handy definitions */
  78. X
  79. X#define Null(t) ((t)0)
  80. X#define Nullch Null(char *)
  81. X#define Nullfp Null(FILE *)
  82. X#define Nulline Null(LINENUM)
  83. X
  84. X#define Ctl(ch) ((ch) & 037)
  85. X
  86. X#define strNE(s1,s2) (strcmp(s1, s2))
  87. X#define strEQ(s1,s2) (!strcmp(s1, s2))
  88. X#define strnNE(s1,s2,l) (strncmp(s1, s2, l))
  89. X#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
  90. X
  91. X/* typedefs */
  92. X
  93. Xtypedef char bool;
  94. Xtypedef long LINENUM;            /* must be signed */
  95. Xtypedef unsigned MEM;            /* what to feed malloc */
  96. X
  97. X/* globals */
  98. X
  99. XEXT int Argc;                /* guess */
  100. XEXT char **Argv;
  101. XEXT int Argc_last;            /* for restarting plan_b */
  102. XEXT char **Argv_last;
  103. X
  104. XEXT struct stat filestat;        /* file statistics area */
  105. XEXT int filemode INIT(0644);
  106. X
  107. XEXT char buf[MAXLINELEN];        /* general purpose buffer */
  108. XEXT FILE *ofp INIT(Nullfp);        /* output file pointer */
  109. XEXT FILE *rejfp INIT(Nullfp);        /* reject file pointer */
  110. X
  111. XEXT bool using_plan_a INIT(TRUE);    /* try to keep everything in memory */
  112. XEXT bool out_of_mem INIT(FALSE);    /* ran out of memory in plan a */
  113. X
  114. X#define MAXFILEC 2
  115. XEXT int filec INIT(0);            /* how many file arguments? */
  116. XEXT char *filearg[MAXFILEC];
  117. XEXT bool ok_to_create_file INIT(FALSE);
  118. XEXT char *bestguess INIT(Nullch);    /* guess at correct filename */
  119. X
  120. XEXT char *outname INIT(Nullch);
  121. XEXT char rejname[128];
  122. X
  123. XEXT char *origext INIT(Nullch);
  124. X
  125. XEXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX");
  126. XEXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX");    /* might want /usr/tmp here */
  127. XEXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX");
  128. XEXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX");
  129. XEXT bool toutkeep INIT(FALSE);
  130. XEXT bool trejkeep INIT(FALSE);
  131. X
  132. XEXT LINENUM last_offset INIT(0);
  133. X#ifdef DEBUGGING
  134. XEXT int debug INIT(0);
  135. X#endif
  136. XEXT LINENUM maxfuzz INIT(2);
  137. XEXT bool force INIT(FALSE);
  138. XEXT bool verbose INIT(TRUE);
  139. XEXT bool reverse INIT(FALSE);
  140. XEXT bool noreverse INIT(FALSE);
  141. XEXT bool skip_rest_of_patch INIT(FALSE);
  142. XEXT int strippath INIT(957);
  143. XEXT bool canonicalize INIT(FALSE);
  144. X
  145. X#define CONTEXT_DIFF 1
  146. X#define NORMAL_DIFF 2
  147. X#define ED_DIFF 3
  148. X#define NEW_CONTEXT_DIFF 4
  149. XEXT int diff_type INIT(0);
  150. X
  151. XEXT bool do_defines INIT(FALSE);    /* patch using ifdef, ifndef, etc. */
  152. XEXT char if_defined[128];        /* #ifdef xyzzy */
  153. XEXT char not_defined[128];        /* #ifndef xyzzy */
  154. XEXT char else_defined[] INIT("#else\n");/* #else */
  155. XEXT char end_defined[128];        /* #endif xyzzy */
  156. X
  157. XEXT char *revision INIT(Nullch);    /* prerequisite revision, if any */
  158. X
  159. Xchar *malloc();
  160. Xchar *realloc();
  161. Xchar *strcpy();
  162. Xchar *strcat();
  163. Xchar *sprintf();        /* usually */
  164. Xlong atol();
  165. Xlong lseek();
  166. Xchar *mktemp();
  167. !STUFFY!FUNK!
  168. echo Extracting README
  169. sed >README <<'!STUFFY!FUNK!' -e 's/X//'
  170. X            Patch Kit, Version 2.0
  171. X
  172. X            Copyright (c) 1986, Larry Wall
  173. X
  174. XYou may copy the patch kit in whole or in part as long as you don't try to
  175. Xmake money off it, or pretend that you wrote it.
  176. X--------------------------------------------------------------------------
  177. X
  178. XPlease read all the directions below before you proceed any further, and
  179. Xthen follow them carefully.  Failure to do so may void your warranty. :-)
  180. X
  181. XAfter you have unpacked your kit, you should have all the files listed
  182. Xin MANIFEST.
  183. X
  184. XInstallation
  185. X
  186. X1)  Run Configure.  This will figure out various things about your system.
  187. X    Some things Configure will figure out for itself, other things it will
  188. X    ask you about.  It will then proceed to make config.h, config.sh, and
  189. X    Makefile.
  190. X
  191. X    You might possibly have to trim # comments from the front of Configure
  192. X    if your sh doesn't handle them, but all other # comments will be taken
  193. X    care of.
  194. X
  195. X    If you don't have sh, you'll have to rip the prototype of config.h out
  196. X    of Configure and generate the defines by hand.
  197. X
  198. X2)  Glance through config.h to make sure system dependencies are correct.
  199. X    Most of them should have been taken care of by running the Configure script.
  200. X
  201. X    If you have any additional changes to make to the C definitions, they
  202. X    can be done in the Makefile, or in config.h.  Bear in mind that they may
  203. X    get undone next time you run Configure.
  204. X
  205. X3)  make
  206. X
  207. X    This will attempt to make patch in the current directory.
  208. X
  209. X4)  make install
  210. X
  211. X    This will put patch into a public directory (normally /usr/local/bin).
  212. X    It will also try to put the man pages in a reasonable place.  It will not
  213. X    nroff the man page, however.
  214. X
  215. X5)  Read the manual entry before running patch.
  216. X
  217. X6)  IMPORTANT!  Help save the world!  Communicate any problems and
  218. X    suggested patches to me, lwall@sdcrdcf.UUCP (Larry Wall), so we can
  219. X    keep the world in sync.  If you have a problem, there's someone else
  220. X    out there who either has had or will have the same problem.
  221. X
  222. X    If possible, send in patches such that the patch program will apply them.
  223. X    Context diffs are the best, then normal diffs.  Don't send ed scripts--
  224. X    I've probably changed my copy since the version you have.
  225. X
  226. X    Watch for patch patches in net.sources.bugs.  Patches will generally be
  227. X    in a form usable by the patch program.  If you are just now bringing up
  228. X    patch and aren't sure how many patches there are, write to me and I'll
  229. X    send any you don't have.  Your current patch level is shown in patchlevel.h.
  230. X
  231. X
  232. XNEW FEATURES IN THIS RELEASE
  233. X
  234. X(Correct) support for 4.3bsd-style context diffs.
  235. XFiles can be created from scratch.
  236. XYou can specify a fuzz-factor for context matching.
  237. XYou can force patch to ask no questions.
  238. XYou can specify how much of the leading pathname to strip off filenames.
  239. XUses a Configure script for greater portability.
  240. XYou are now asked if you want to apply a reversed patch.
  241. XNo limit (apart from memory) on the size of hunks.
  242. !STUFFY!FUNK!
  243. echo Extracting Makefile.SH
  244. sed >Makefile.SH <<'!STUFFY!FUNK!' -e 's/X//'
  245. Xcase $CONFIG in
  246. X    '') . config.sh ;;
  247. Xesac
  248. Xecho "Extracting Makefile (with variable substitutions)"
  249. Xcat >Makefile <<!GROK!THIS!
  250. X# $Header: Makefile.SH,v 2.0 86/09/17 15:36:15 lwall Exp $
  251. X#
  252. X# $Log:    Makefile.SH,v $
  253. X# Revision 2.0  86/09/17  15:36:15  lwall
  254. X# Baseline for netwide release.
  255. X# 
  256. X# Revision 1.2  86/09/08  14:07:42  lwall
  257. X# Split up patch.c.
  258. X# 
  259. X# Revision 1.1  86/08/01  20:18:35  lwall
  260. X# Initial revision
  261. X# 
  262. X
  263. XCC = $cc
  264. Xbin = $bin
  265. Xmansrc = $mansrc
  266. Xmanext = $manext
  267. XCFLAGS = $iandd -O
  268. XLDFLAGS = $iandd
  269. X
  270. X!GROK!THIS!
  271. Xcat >>Makefile <<'!NO!SUBS!'
  272. X
  273. Xpublic = patch
  274. Xprivate = 
  275. Xmanpages = patch.man
  276. Xutil = Makefile
  277. X
  278. Xc = patch.c pch.c inp.c version.c util.c
  279. X
  280. Xobj = patch.o pch.o inp.o util.o version.o
  281. X
  282. Xlintflags = -phbvxac
  283. X
  284. Xaddedbyconf = Makefile.old bsd config.h config.sh eunice loc pdp11 usg v7
  285. X
  286. X# grrr
  287. XSHELL = /bin/sh
  288. X
  289. X.c.o:
  290. X    $(CC) -c $(CFLAGS) $*.c
  291. X
  292. Xall: $(public) $(private) $(util)
  293. X    touch all
  294. X
  295. Xpatch: $(obj)
  296. X    $(CC) $(LDFLAGS) $(obj) $(libs) -o patch
  297. X
  298. X# won't work with csh
  299. Xinstall: patch
  300. X    export PATH || exit 1
  301. X    - mv $(bin)/patch $(bin)/patch.old
  302. X    - if test `pwd` != $(bin); then cp $(public) $(bin); fi
  303. X    cd $(bin); chmod 755 $(public)
  304. X    - if test `pwd` != $(mansrc); then \
  305. Xfor page in $(manpages); do \
  306. Xcp $$page $(mansrc)/`basename $$page .man`.$(manext); \
  307. Xdone; \
  308. Xfi
  309. X
  310. Xclean:
  311. X    rm -f *.o *.orig core
  312. X
  313. Xrealclean:
  314. X    rm -f patch *.o *.orig core $(addedbyconf)
  315. X
  316. X# The following lint has practically everything turned on.  Unfortunately,
  317. X# you have to wade through a lot of mumbo jumbo that can't be suppressed.
  318. X# If the source file has a /*NOSTRICT*/ somewhere, ignore the lint message
  319. X# for that spot.
  320. X
  321. Xlint:
  322. X    lint $(lintflags) $(defs) $(c) > patch.fuzz
  323. X
  324. Xpatch.o: config.h common.h patch.c inp.h pch.h util.h version.h
  325. Xpch.o: config.h common.h pch.c pch.h util.h
  326. Xinp.o: config.h common.h inp.c inp.h util.h
  327. Xutil.o: config.h common.h util.c util.h
  328. Xversion.o: config.h common.h version.c version.h patchlevel.h util.h
  329. X
  330. X!NO!SUBS!
  331. X$eunicefix Makefile
  332. !STUFFY!FUNK!
  333. echo Extracting MANIFEST
  334. sed >MANIFEST <<'!STUFFY!FUNK!' -e 's/X//'
  335. XAfter all the patch kits are run you should have the following files:
  336. X
  337. XFilename        Kit Description
  338. X--------        --- -----------
  339. XConfigure                1  A shell script that installs everything system dependent.
  340. XEXTERN.h                 1  Toggle .h files to look foreign.
  341. XINTERN.h                 3  Toggle .h files to look domestic.
  342. XMANIFEST                 3  This list of files.
  343. XMakefile.SH              3  The makefile.
  344. XREADME                   3  Installation instructions.
  345. Xcommon.h                 3  Common definitions.
  346. Xconfig.H                 3  Sample config.h, in case Configure won't run.
  347. Xinp.c                    2  Input file abstract data type routines.
  348. Xinp.h                    3  Public defs for above.
  349. Xpatch.c                  2  The patch program.
  350. Xpatch.man                2  Manual page for patch.
  351. Xpatchlevel.h             3  The patch level of the patch program.
  352. Xpch.c                    1  Patch abstract data type routines.
  353. Xpch.h                    3  Public defs for above.
  354. Xutil.c                   2  Utility routines.
  355. Xutil.h                   1  Public defs for above.
  356. Xversion.c                3  Version number routine.
  357. Xversion.h                3  Public defs for above.
  358. !STUFFY!FUNK!
  359. echo Extracting pch.h
  360. sed >pch.h <<'!STUFFY!FUNK!' -e 's/X//'
  361. X/* $Header: pch.h,v 2.0 86/09/17 15:39:57 lwall Exp $
  362. X *
  363. X * $Log:    pch.h,v $
  364. X * Revision 2.0  86/09/17  15:39:57  lwall
  365. X * Baseline for netwide release.
  366. X * 
  367. X */
  368. X
  369. XEXT FILE *pfp INIT(Nullfp);        /* patch file pointer */
  370. X
  371. Xvoid re_patch();
  372. Xvoid open_patch_file();
  373. Xvoid set_hunkmax();
  374. Xvoid grow_hunkmax();
  375. Xbool there_is_another_patch();
  376. Xint intuit_diff_type();
  377. Xvoid next_intuit_at();
  378. Xvoid skip_to();
  379. Xbool another_hunk();
  380. Xbool pch_swap();
  381. Xchar *pfetch();
  382. Xshort pch_line_len();
  383. XLINENUM pch_first();
  384. XLINENUM pch_ptrn_lines();
  385. XLINENUM pch_newfirst();
  386. XLINENUM pch_repl_lines();
  387. XLINENUM pch_end();
  388. XLINENUM pch_context();
  389. XLINENUM pch_hunk_beg();
  390. Xchar pch_char();
  391. Xchar *pfetch();
  392. Xchar *pgets();
  393. !STUFFY!FUNK!
  394. echo Extracting config.H
  395. sed >config.H <<'!STUFFY!FUNK!' -e 's/X//'
  396. X/* config.h
  397. X * This file was produced by running the Configure script.
  398. X * Feel free to modify any of this as the need arises.
  399. X */
  400. X
  401. X
  402. X#/*undef    EUNICE        /* no file linking? */
  403. X#/*undef    VMS
  404. X
  405. X#/*undef    index strchr    /* cultural */
  406. X#/*undef    rindex strrchr    /*  differences? */
  407. X
  408. X#/*undef    void int    /* is void to be avoided? */
  409. X
  410. X/* How many register declarations are paid attention to? */
  411. X
  412. X#define Reg1 register
  413. X#define Reg2 register
  414. X#define Reg3 register
  415. X#define Reg4 register
  416. X#define Reg5 register
  417. X#define Reg6 register
  418. X#define Reg7 
  419. X#define Reg8 
  420. X#define Reg9 
  421. X#define Reg10 
  422. X#define Reg11 
  423. X#define Reg12 
  424. X#define Reg13 
  425. X#define Reg14 
  426. X#define Reg15 
  427. X#define Reg16 
  428. X
  429. !STUFFY!FUNK!
  430. echo Extracting version.c
  431. sed >version.c <<'!STUFFY!FUNK!' -e 's/X//'
  432. X/* $Header: version.c,v 2.0 86/09/17 15:40:11 lwall Exp $
  433. X *
  434. X * $Log:    version.c,v $
  435. X * Revision 2.0  86/09/17  15:40:11  lwall
  436. X * Baseline for netwide release.
  437. X * 
  438. X */
  439. X
  440. X#include "EXTERN.h"
  441. X#include "common.h"
  442. X#include "util.h"
  443. X#include "INTERN.h"
  444. X#include "patchlevel.h"
  445. X#include "version.h"
  446. X
  447. X/* Print out the version number and die. */
  448. X
  449. Xvoid
  450. Xversion()
  451. X{
  452. X    extern char rcsid[];
  453. X
  454. X#ifdef lint
  455. X    rcsid[0] = rcsid[0];
  456. X#else
  457. X    fatal3("%s\nPatch level: %d\n", rcsid, PATCHLEVEL);
  458. X#endif
  459. X}
  460. !STUFFY!FUNK!
  461. echo Extracting inp.h
  462. sed >inp.h <<'!STUFFY!FUNK!' -e 's/X//'
  463. X/* $Header: inp.h,v 2.0 86/09/17 15:37:25 lwall Exp $
  464. X *
  465. X * $Log:    inp.h,v $
  466. X * Revision 2.0  86/09/17  15:37:25  lwall
  467. X * Baseline for netwide release.
  468. X * 
  469. X */
  470. X
  471. XEXT LINENUM input_lines INIT(0);    /* how long is input file in lines */
  472. XEXT LINENUM last_frozen_line INIT(0);    /* how many input lines have been */
  473. X                    /* irretractibly output */
  474. X
  475. Xbool rev_in_string();
  476. Xvoid scan_input();
  477. Xbool plan_a();            /* returns false if insufficient memory */
  478. Xvoid plan_b();
  479. Xchar *ifetch();
  480. X
  481. !STUFFY!FUNK!
  482. echo Extracting INTERN.h
  483. sed >INTERN.h <<'!STUFFY!FUNK!' -e 's/X//'
  484. X/* $Header: INTERN.h,v 2.0 86/09/17 15:35:58 lwall Exp $
  485. X *
  486. X * $Log:    INTERN.h,v $
  487. X * Revision 2.0  86/09/17  15:35:58  lwall
  488. X * Baseline for netwide release.
  489. X * 
  490. X */
  491. X
  492. X#undef EXT
  493. X#define EXT
  494. X
  495. X#undef INIT
  496. X#define INIT(x) = x
  497. X
  498. X#define DOINIT
  499. !STUFFY!FUNK!
  500. echo Extracting version.h
  501. sed >version.h <<'!STUFFY!FUNK!' -e 's/X//'
  502. X/* $Header: version.h,v 2.0 86/09/17 15:40:14 lwall Exp $
  503. X *
  504. X * $Log:    version.h,v $
  505. X * Revision 2.0  86/09/17  15:40:14  lwall
  506. X * Baseline for netwide release.
  507. X * 
  508. X */
  509. X
  510. Xvoid version();
  511. !STUFFY!FUNK!
  512. echo Extracting patchlevel.h
  513. sed >patchlevel.h <<'!STUFFY!FUNK!' -e 's/X//'
  514. X#define PATCHLEVEL 0
  515. !STUFFY!FUNK!
  516. echo ""
  517. echo "End of kit 3 (of 3)"
  518. cat /dev/null >kit3isdone
  519. config=true
  520. for iskit in 1 2 3; do
  521.     if test -f kit${iskit}isdone; then
  522.     echo "You have run kit ${iskit}."
  523.     else
  524.     echo "You still need to run kit ${iskit}."
  525.     config=false
  526.     fi
  527. done
  528. case $config in
  529.     true)
  530.     echo "You have run all your kits.  Please read README and then type Configure."
  531.     chmod 755 Configure
  532.     ;;
  533. esac
  534. : I do not append .signature, but someone might mail this.
  535. exit
  536.  
  537.