home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume7 / patch2 / part01 next >
Text File  |  1986-11-30  |  51KB  |  2,112 lines

  1. Subject:  v07i038:  Release 2.0 of patch, Part01/03
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: sdcrdcf!lwall (Larry Wall)
  6. Mod.sources: Volume 7, Issue 38
  7. Archive-name: patch2/Part01
  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 1 (of 3).  If kit 1 is complete, the line"
  22. echo '"'"End of kit 1 (of 3)"'" will echo at the end.'
  23. echo ""
  24. export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
  25. echo Extracting pch.c
  26. sed >pch.c <<'!STUFFY!FUNK!' -e 's/X//'
  27. X/* $Header: pch.c,v 2.0 86/09/17 15:39:37 lwall Exp $
  28. X *
  29. X * $Log:    pch.c,v $
  30. X * Revision 2.0  86/09/17  15:39:37  lwall
  31. X * Baseline for netwide release.
  32. X * 
  33. X */
  34. X
  35. X#include "EXTERN.h"
  36. X#include "common.h"
  37. X#include "util.h"
  38. X#include "INTERN.h"
  39. X#include "pch.h"
  40. X
  41. X/* Patch (diff listing) abstract type. */
  42. X
  43. Xstatic long p_filesize;            /* size of the patch file */
  44. Xstatic LINENUM p_first;            /* 1st line number */
  45. Xstatic LINENUM p_newfirst;        /* 1st line number of replacement */
  46. Xstatic LINENUM p_ptrn_lines;        /* # lines in pattern */
  47. Xstatic LINENUM p_repl_lines;        /* # lines in replacement text */
  48. Xstatic LINENUM p_end = -1;        /* last line in hunk */
  49. Xstatic LINENUM p_max;            /* max allowed value of p_end */
  50. Xstatic LINENUM p_context = 3;        /* # of context lines */
  51. Xstatic LINENUM p_input_line = 0;    /* current line # from patch file */
  52. Xstatic char **p_line = Null(char**);    /* the text of the hunk */
  53. Xstatic short *p_len = Null(short*);    /* length of each line */
  54. Xstatic char *p_char = Nullch;        /* +, -, and ! */
  55. Xstatic int hunkmax = INITHUNKMAX;    /* size of above arrays to begin with */
  56. Xstatic int p_indent;            /* indent to patch */
  57. Xstatic LINENUM p_base;            /* where to intuit this time */
  58. Xstatic LINENUM p_start;            /* where intuit found a patch */
  59. X
  60. X/* Prepare to look for the next patch in the patch file. */
  61. X
  62. Xvoid
  63. Xre_patch()
  64. X{
  65. X    p_first = Nulline;
  66. X    p_newfirst = Nulline;
  67. X    p_ptrn_lines = Nulline;
  68. X    p_repl_lines = Nulline;
  69. X    p_end = (LINENUM)-1;
  70. X    p_max = Nulline;
  71. X    p_indent = 0;
  72. X}
  73. X
  74. X/* Open the patch file at the beginning of time. */
  75. X
  76. Xvoid
  77. Xopen_patch_file(filename)
  78. Xchar *filename;
  79. X{
  80. X    if (filename == Nullch || !*filename || strEQ(filename, "-")) {
  81. X    pfp = fopen(TMPPATNAME, "w");
  82. X    if (pfp == Nullfp)
  83. X        fatal2("patch: can't create %s.\n", TMPPATNAME);
  84. X    while (fgets(buf, sizeof buf, stdin) != Nullch)
  85. X        fputs(buf, pfp);
  86. X    Fclose(pfp);
  87. X    filename = TMPPATNAME;
  88. X    }
  89. X    pfp = fopen(filename, "r");
  90. X    if (pfp == Nullfp)
  91. X    fatal2("patch file %s not found\n", filename);
  92. X    Fstat(fileno(pfp), &filestat);
  93. X    p_filesize = filestat.st_size;
  94. X    next_intuit_at(0L);            /* start at the beginning */
  95. X    set_hunkmax();
  96. X}
  97. X
  98. X/* Make sure our dynamically realloced tables are malloced to begin with. */
  99. X
  100. Xvoid
  101. Xset_hunkmax()
  102. X{
  103. X#ifndef lint
  104. X    if (p_line == Null(char**))
  105. X    p_line = (char**) malloc((MEM)hunkmax * sizeof(char *));
  106. X    if (p_len == Null(short*))
  107. X    p_len  = (short*) malloc((MEM)hunkmax * sizeof(short));
  108. X#endif
  109. X    if (p_char == Nullch)
  110. X    p_char = (char*)  malloc((MEM)hunkmax * sizeof(char));
  111. X}
  112. X
  113. X/* Enlarge the arrays containing the current hunk of patch. */
  114. X
  115. Xvoid
  116. Xgrow_hunkmax()
  117. X{
  118. X    hunkmax *= 2;
  119. X    /* 
  120. X     * Note that on most systems, only the p_line array ever gets fresh memory
  121. X     * since p_len can move into p_line's old space, and p_char can move into
  122. X     * p_len's old space.  Not on PDP-11's however.  But it doesn't matter.
  123. X     */
  124. X    assert(p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch);
  125. X#ifndef lint
  126. X    p_line = (char**) realloc((char*)p_line, (MEM)hunkmax * sizeof(char *));
  127. X    p_len  = (short*) realloc((char*)p_len,  (MEM)hunkmax * sizeof(short));
  128. X    p_char = (char*)  realloc((char*)p_char, (MEM)hunkmax * sizeof(char));
  129. X#endif
  130. X    if (p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch)
  131. X    return;
  132. X    if (!using_plan_a)
  133. X    fatal1("patch: out of memory (grow_hunkmax)\n");
  134. X    out_of_mem = TRUE;        /* whatever is null will be allocated again */
  135. X                /* from within plan_a(), of all places */
  136. X}
  137. X
  138. X/* True if the remainder of the patch file contains a diff of some sort. */
  139. X
  140. Xbool
  141. Xthere_is_another_patch()
  142. X{
  143. X    if (p_base != 0L && p_base >= p_filesize) {
  144. X    if (verbose)
  145. X        say1("done\n");
  146. X    return FALSE;
  147. X    }
  148. X    if (verbose)
  149. X    say1("Hmm...");
  150. X    diff_type = intuit_diff_type();
  151. X    if (!diff_type) {
  152. X    if (p_base != 0L) {
  153. X        if (verbose)
  154. X        say1("  Ignoring the trailing garbage.\ndone\n");
  155. X    }
  156. X    else
  157. X        say1("  I can't seem to find a patch in there anywhere.\n");
  158. X    return FALSE;
  159. X    }
  160. X    if (verbose)
  161. X    say3("  %sooks like %s to me...\n",
  162. X        (p_base == 0L ? "L" : "The next patch l"),
  163. X        diff_type == CONTEXT_DIFF ? "a context diff" :
  164. X        diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
  165. X        diff_type == NORMAL_DIFF ? "a normal diff" :
  166. X        "an ed script" );
  167. X    if (p_indent && verbose)
  168. X    say3("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s");
  169. X    skip_to(p_start);
  170. X    while (filearg[0] == Nullch) {
  171. X    if (force) {
  172. X        say1("No file to patch.  Skipping...\n");
  173. X        filearg[0] = savestr(bestguess);
  174. X        return TRUE;
  175. X    }
  176. X    ask1("File to patch: ");
  177. X    if (*buf != '\n') {
  178. X        if (bestguess)
  179. X        free(bestguess);
  180. X        bestguess = savestr(buf);
  181. X        filearg[0] = fetchname(buf, 0, FALSE);
  182. X    }
  183. X    if (filearg[0] == Nullch) {
  184. X        ask1("No file found--skip this patch? [n] ");
  185. X        if (*buf != 'y') {
  186. X        continue;
  187. X        }
  188. X        if (verbose)
  189. X        say1("Skipping patch...\n");
  190. X        filearg[0] = fetchname(bestguess, 0, TRUE);
  191. X        skip_rest_of_patch = TRUE;
  192. X        return TRUE;
  193. X    }
  194. X    }
  195. X    return TRUE;
  196. X}
  197. X
  198. X/* Determine what kind of diff is in the remaining part of the patch file. */
  199. X
  200. Xint
  201. Xintuit_diff_type()
  202. X{
  203. X    Reg4 long this_line = 0;
  204. X    Reg5 long previous_line;
  205. X    Reg6 long first_command_line = -1;
  206. X    Reg7 bool last_line_was_command = FALSE;
  207. X    Reg8 bool this_is_a_command = FALSE;
  208. X    Reg9 bool stars_last_line = FALSE;
  209. X    Reg10 bool stars_this_line = FALSE;
  210. X    Reg3 int indent;
  211. X    Reg1 char *s;
  212. X    Reg2 char *t;
  213. X    char *indtmp = Nullch;
  214. X    char *oldtmp = Nullch;
  215. X    char *newtmp = Nullch;
  216. X    char *indname = Nullch;
  217. X    char *oldname = Nullch;
  218. X    char *newname = Nullch;
  219. X    Reg11 int retval;
  220. X    bool no_filearg = (filearg[0] == Nullch);
  221. X
  222. X    ok_to_create_file = FALSE;
  223. X    Fseek(pfp, p_base, 0);
  224. X    for (;;) {
  225. X    previous_line = this_line;
  226. X    last_line_was_command = this_is_a_command;
  227. X    stars_last_line = stars_this_line;
  228. X    this_line = ftell(pfp);
  229. X    indent = 0;
  230. X    if (fgets(buf, sizeof buf, pfp) == Nullch) {
  231. X        if (first_command_line >= 0L) {
  232. X                    /* nothing but deletes!? */
  233. X        p_start = first_command_line;
  234. X        retval = ED_DIFF;
  235. X        goto scan_exit;
  236. X        }
  237. X        else {
  238. X        p_start = this_line;
  239. X        retval = 0;
  240. X        goto scan_exit;
  241. X        }
  242. X    }
  243. X    for (s = buf; *s == ' ' || *s == '\t'; s++) {
  244. X        if (*s == '\t')
  245. X        indent += 8 - (indent % 8);
  246. X        else
  247. X        indent++;
  248. X    }
  249. X    for (t=s; isdigit(*t) || *t == ','; t++) ; 
  250. X    this_is_a_command = (isdigit(*s) &&
  251. X      (*t == 'd' || *t == 'c' || *t == 'a') );
  252. X    if (first_command_line < 0L && this_is_a_command) { 
  253. X        first_command_line = this_line;
  254. X        p_indent = indent;        /* assume this for now */
  255. X    }
  256. X    if (!stars_last_line && strnEQ(s, "*** ", 4))
  257. X        oldtmp = savestr(s+4);
  258. X    else if (strnEQ(s, "--- ", 4))
  259. X        newtmp = savestr(s+4);
  260. X    else if (strnEQ(s, "Index:", 6))
  261. X        indtmp = savestr(s+6);
  262. X    else if (strnEQ(s, "Prereq:", 7)) {
  263. X        for (t=s+7; isspace(*t); t++) ;
  264. X        revision = savestr(t);
  265. X        for (t=revision; *t && !isspace(*t); t++) ;
  266. X        *t = '\0';
  267. X        if (!*revision) {
  268. X        free(revision);
  269. X        revision = Nullch;
  270. X        }
  271. X    }
  272. X    if ((!diff_type || diff_type == ED_DIFF) &&
  273. X      first_command_line >= 0L &&
  274. X      strEQ(s, ".\n") ) {
  275. X        p_indent = indent;
  276. X        p_start = first_command_line;
  277. X        retval = ED_DIFF;
  278. X        goto scan_exit;
  279. X    }
  280. X    stars_this_line = strnEQ(s, "********", 8);
  281. X    if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line &&
  282. X         strnEQ(s, "*** ", 4)) {
  283. X        if (!atol(s+4))
  284. X        ok_to_create_file = TRUE;
  285. X        /* if this is a new context diff the character just before */
  286. X        /* the newline is a '*'. */
  287. X        while (*s != '\n')
  288. X        s++;
  289. X        p_indent = indent;
  290. X        p_start = previous_line;
  291. X        retval = (*(s-1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF);
  292. X        goto scan_exit;
  293. X    }
  294. X    if ((!diff_type || diff_type == NORMAL_DIFF) && 
  295. X      last_line_was_command &&
  296. X      (strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) {
  297. X        p_start = previous_line;
  298. X        p_indent = indent;
  299. X        retval = NORMAL_DIFF;
  300. X        goto scan_exit;
  301. X    }
  302. X    }
  303. X  scan_exit:
  304. X    if (no_filearg) {
  305. X    if (indtmp != Nullch)
  306. X        indname = fetchname(indtmp, strippath, ok_to_create_file);
  307. X    if (oldtmp != Nullch)
  308. X        oldname = fetchname(oldtmp, strippath, ok_to_create_file);
  309. X    if (newtmp != Nullch)
  310. X        newname = fetchname(newtmp, strippath, ok_to_create_file);
  311. X    if (oldname && newname) {
  312. X        if (strlen(oldname) < strlen(newname))
  313. X        filearg[0] = savestr(oldname);
  314. X        else
  315. X        filearg[0] = savestr(newname);
  316. X    }
  317. X    else if (oldname)
  318. X        filearg[0] = savestr(oldname);
  319. X    else if (newname)
  320. X        filearg[0] = savestr(newname);
  321. X    else if (indname)
  322. X        filearg[0] = savestr(indname);
  323. X    }
  324. X    if (bestguess) {
  325. X    free(bestguess);
  326. X    bestguess = Nullch;
  327. X    }
  328. X    if (filearg[0] != Nullch)
  329. X    bestguess = savestr(filearg[0]);
  330. X    else if (indtmp != Nullch)
  331. X    bestguess = fetchname(indtmp, strippath, TRUE);
  332. X    else {
  333. X    if (oldtmp != Nullch)
  334. X        oldname = fetchname(oldtmp, strippath, TRUE);
  335. X    if (newtmp != Nullch)
  336. X        newname = fetchname(newtmp, strippath, TRUE);
  337. X    if (oldname && newname) {
  338. X        if (strlen(oldname) < strlen(newname))
  339. X        bestguess = savestr(oldname);
  340. X        else
  341. X        bestguess = savestr(newname);
  342. X    }
  343. X    else if (oldname)
  344. X        bestguess = savestr(oldname);
  345. X    else if (newname)
  346. X        bestguess = savestr(newname);
  347. X    }
  348. X    if (indtmp != Nullch)
  349. X    free(indtmp);
  350. X    if (oldtmp != Nullch)
  351. X    free(oldtmp);
  352. X    if (newtmp != Nullch)
  353. X    free(newtmp);
  354. X    if (indname != Nullch)
  355. X    free(indname);
  356. X    if (oldname != Nullch)
  357. X    free(oldname);
  358. X    if (newname != Nullch)
  359. X    free(newname);
  360. X    return retval;
  361. X}
  362. X
  363. X/* Remember where this patch ends so we know where to start up again. */
  364. X
  365. Xvoid
  366. Xnext_intuit_at(file_pos)
  367. Xlong file_pos;
  368. X{
  369. X    p_base = file_pos;
  370. X}
  371. X
  372. X/* Basically a verbose fseek() to the actual diff listing. */
  373. X
  374. Xvoid
  375. Xskip_to(file_pos)
  376. Xlong file_pos;
  377. X{
  378. X    char *ret;
  379. X
  380. X    assert(p_base <= file_pos);
  381. X    if (verbose && p_base < file_pos) {
  382. X    Fseek(pfp, p_base, 0);
  383. X    say1("The text leading up to this was:\n--------------------------\n");
  384. X    while (ftell(pfp) < file_pos) {
  385. X        ret = fgets(buf, sizeof buf, pfp);
  386. X        assert(ret != Nullch);
  387. X        say2("|%s", buf);
  388. X    }
  389. X    say1("--------------------------\n");
  390. X    }
  391. X    else
  392. X    Fseek(pfp, file_pos, 0);
  393. X}
  394. X
  395. X/* True if there is more of the current diff listing to process. */
  396. X
  397. Xbool
  398. Xanother_hunk()
  399. X{
  400. X    Reg1 char *s;
  401. X    Reg8 char *ret;
  402. X    Reg2 int context = 0;
  403. X
  404. X    while (p_end >= 0) {
  405. X    free(p_line[p_end]);        /* Changed from postdecrement */
  406. X    p_end--;            /* by Keenan Ross for BSD2.9  */
  407. X    }
  408. X    assert(p_end == -1);
  409. X
  410. X    p_max = hunkmax;            /* gets reduced when --- found */
  411. X    if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) {
  412. X    long line_beginning = ftell(pfp);
  413. X                    /* file pos of the current line */
  414. X    LINENUM repl_beginning = 0;    /* index of --- line */
  415. X    Reg4 LINENUM fillcnt = 0;    /* #lines of missing ptrn or repl */
  416. X    Reg5 LINENUM fillsrc;        /* index of first line to copy */
  417. X    Reg6 LINENUM filldst;        /* index of first missing line */
  418. X    bool ptrn_spaces_eaten = FALSE;    /* ptrn was slightly misformed */
  419. X    Reg9 bool repl_could_be_missing = TRUE;
  420. X                    /* no + or ! lines in this hunk */
  421. X    bool repl_missing = FALSE;    /* we are now backtracking */
  422. X    long repl_backtrack_position = 0;
  423. X                    /* file pos of first repl line */
  424. X    Reg7 LINENUM ptrn_copiable = 0;
  425. X                    /* # of copiable lines in ptrn */
  426. X
  427. X    ret = pgets(buf, sizeof buf, pfp);
  428. X    if (ret == Nullch || strnNE(buf, "********", 8)) {
  429. X        next_intuit_at(line_beginning);
  430. X        return FALSE;
  431. X    }
  432. X    p_context = 100;
  433. X    while (p_end < p_max) {
  434. X        line_beginning = ftell(pfp);
  435. X        ret = pgets(buf, sizeof buf, pfp);
  436. X        if (ret == Nullch) {
  437. X        if (p_max - p_end < 4)
  438. X            Strcpy(buf, "  \n");  /* assume blank lines got chopped */
  439. X        else {
  440. X            if (repl_beginning && repl_could_be_missing) {
  441. X            repl_missing = TRUE;
  442. X            goto hunk_done;
  443. X            }
  444. X            fatal1("Unexpected end of file in patch.\n");
  445. X        }
  446. X        }
  447. X        p_input_line++;
  448. X        p_char[++p_end] = *buf;
  449. X        p_line[p_end] = Nullch;
  450. X        switch (*buf) {
  451. X        case '*':
  452. X        if (strnEQ(buf, "********", 8)) {
  453. X            if (repl_beginning && repl_could_be_missing) {
  454. X            repl_missing = TRUE;
  455. X            goto hunk_done;
  456. X            }
  457. X            else
  458. X            fatal2("Unexpected end of hunk at line %ld.\n",
  459. X                p_input_line);
  460. X        }
  461. X        if (p_end != 0) {
  462. X            if (repl_beginning && repl_could_be_missing) {
  463. X            repl_missing = TRUE;
  464. X            goto hunk_done;
  465. X            }
  466. X            fatal3("Unexpected *** at line %ld: %s", p_input_line, buf);
  467. X        }
  468. X        context = 0;
  469. X        p_line[p_end] = savestr(buf);
  470. X        if (out_of_mem) {
  471. X            p_end--;
  472. X            return FALSE;
  473. X        }
  474. X        for (s=buf; *s && !isdigit(*s); s++) ;
  475. X        if (!*s)
  476. X            goto malformed;
  477. X        p_first = (LINENUM) atol(s);
  478. X        while (isdigit(*s)) s++;
  479. X        if (*s == ',') {
  480. X            for (; *s && !isdigit(*s); s++) ;
  481. X            if (!*s)
  482. X            goto malformed;
  483. X            p_ptrn_lines = ((LINENUM)atol(s)) - p_first + 1;
  484. X        }
  485. X        else if (p_first)
  486. X            p_ptrn_lines = 1;
  487. X        else {
  488. X            p_ptrn_lines = 0;
  489. X            p_first = 1;
  490. X        }
  491. X        break;
  492. X        case '-':
  493. X        if (buf[1] == '-') {
  494. X            if (p_end != p_ptrn_lines + 1 &&
  495. X            p_end != p_ptrn_lines + 2) {
  496. X            if (p_end == 1) {
  497. X                /* `old' lines were omitted - set up to fill */
  498. X                /* them in from 'new' context lines. */
  499. X                p_end = p_ptrn_lines + 1;
  500. X                fillsrc = p_end + 1;
  501. X                filldst = 1;
  502. X                fillcnt = p_ptrn_lines;
  503. X            }
  504. X            else {
  505. X                if (repl_beginning && repl_could_be_missing){
  506. X                repl_missing = TRUE;
  507. X                goto hunk_done;
  508. X                }
  509. X                fatal3("Unexpected --- at line %ld: %s",
  510. X                p_input_line, buf);
  511. X            }
  512. X            }
  513. X            repl_beginning = p_end;
  514. X            repl_backtrack_position = ftell(pfp);
  515. X            p_line[p_end] = savestr(buf);
  516. X            if (out_of_mem) {
  517. X            p_end--;
  518. X            return FALSE;
  519. X            }
  520. X            p_char[p_end] = '=';
  521. X            for (s=buf; *s && !isdigit(*s); s++) ;
  522. X            if (!*s)
  523. X            goto malformed;
  524. X            p_newfirst = (LINENUM) atol(s);
  525. X            while (isdigit(*s)) s++;
  526. X            if (*s == ',') {
  527. X            for (; *s && !isdigit(*s); s++) ;
  528. X            if (!*s)
  529. X                goto malformed;
  530. X            p_repl_lines = ((LINENUM)atol(s)) - p_newfirst + 1;
  531. X            }
  532. X            else if (p_newfirst)
  533. X            p_repl_lines = 1;
  534. X            else {
  535. X            p_repl_lines = 0;
  536. X            p_newfirst = 1;
  537. X            }
  538. X            p_max = p_repl_lines + p_end;
  539. X            if (p_max > MAXHUNKSIZE)
  540. X            fatal4("Hunk too large (%ld lines) at line %ld: %s",
  541. X                  p_max, p_input_line, buf);
  542. X            while (p_max >= hunkmax)
  543. X            grow_hunkmax();
  544. X            if (p_repl_lines != ptrn_copiable)
  545. X            repl_could_be_missing = FALSE;
  546. X            break;
  547. X        }
  548. X        goto change_line;
  549. X        case '+':  case '!':
  550. X        repl_could_be_missing = FALSE;
  551. X          change_line:
  552. X        if (!isspace(buf[1]) && buf[1] != '>' && buf[1] != '<' &&
  553. X          repl_beginning && repl_could_be_missing) {
  554. X            repl_missing = TRUE;
  555. X            goto hunk_done;
  556. X        }
  557. X        if (context > 0) {
  558. X            if (context < p_context)
  559. X            p_context = context;
  560. X            context = -1000;
  561. X        }
  562. X        p_line[p_end] = savestr(buf+2);
  563. X        if (out_of_mem) {
  564. X            p_end--;
  565. X            return FALSE;
  566. X        }
  567. X        break;
  568. X        case '\t': case '\n':    /* assume the 2 spaces got eaten */
  569. X        if (repl_beginning && repl_could_be_missing &&
  570. X          (!ptrn_spaces_eaten || diff_type == NEW_CONTEXT_DIFF) ) {
  571. X            repl_missing = TRUE;
  572. X            goto hunk_done;
  573. X        }
  574. X        p_line[p_end] = savestr(buf);
  575. X        if (out_of_mem) {
  576. X            p_end--;
  577. X            return FALSE;
  578. X        }
  579. X        if (p_end != p_ptrn_lines + 1) {
  580. X            ptrn_spaces_eaten |= (repl_beginning != 0);
  581. X            context++;
  582. X            if (!repl_beginning)
  583. X            ptrn_copiable++;
  584. X            p_char[p_end] = ' ';
  585. X        }
  586. X        break;
  587. X        case ' ':
  588. X        if (!isspace(buf[1]) &&
  589. X          repl_beginning && repl_could_be_missing) {
  590. X            repl_missing = TRUE;
  591. X            goto hunk_done;
  592. X        }
  593. X        context++;
  594. X        if (!repl_beginning)
  595. X            ptrn_copiable++;
  596. X        p_line[p_end] = savestr(buf+2);
  597. X        if (out_of_mem) {
  598. X            p_end--;
  599. X            return FALSE;
  600. X        }
  601. X        break;
  602. X        default:
  603. X        if (repl_beginning && repl_could_be_missing) {
  604. X            repl_missing = TRUE;
  605. X            goto hunk_done;
  606. X        }
  607. X        goto malformed;
  608. X        }
  609. X        /* set up p_len for strncmp() so we don't have to */
  610. X        /* assume null termination */
  611. X        if (p_line[p_end])
  612. X        p_len[p_end] = strlen(p_line[p_end]);
  613. X        else
  614. X        p_len[p_end] = 0;
  615. X    }
  616. X    
  617. X    hunk_done:
  618. X    if (p_end >=0 && !repl_beginning)
  619. X        fatal2("No --- found in patch at line %ld\n", pch_hunk_beg());
  620. X
  621. X    if (repl_missing) {
  622. X        
  623. X        /* reset state back to just after --- */
  624. X        for (p_end--; p_end > repl_beginning; p_end--)
  625. X        free(p_line[p_end]);
  626. X        Fseek(pfp, repl_backtrack_position, 0);
  627. X        
  628. X        /* redundant 'new' context lines were omitted - set */
  629. X        /* up to fill them in from the old file context */
  630. X        fillsrc = 1;
  631. X        filldst = repl_beginning+1;
  632. X        fillcnt = p_repl_lines;
  633. X        p_end = p_max;
  634. X    }
  635. X
  636. X    if (diff_type == CONTEXT_DIFF &&
  637. X      (fillcnt || ptrn_copiable > 2*p_context) ) {
  638. X        if (verbose)
  639. X        say1("\
  640. X(Fascinating--this is really a new-style context diff but without the telltale\n\
  641. Xextra asterisks on the *** line that usually indicate the new style...)\n");
  642. X        diff_type = NEW_CONTEXT_DIFF;
  643. X    }
  644. X    
  645. X    /* if there were omitted context lines, fill them in now */
  646. X    if (fillcnt) {
  647. X        while (fillcnt-- > 0) {
  648. X        while (p_char[fillsrc] != ' ')
  649. X            fillsrc++;
  650. X        p_line[filldst] = p_line[fillsrc];
  651. X        p_char[filldst] = p_char[fillsrc];
  652. X        p_len[filldst] = p_len[fillsrc];
  653. X        fillsrc++; filldst++;
  654. X        }
  655. X        while (fillsrc <= p_end && p_char[fillsrc] != ' ')
  656. X        fillsrc++;
  657. X#ifdef DEBUGGING
  658. X        if (debug & 64)
  659. X        printf("fillsrc %ld, filldst %ld, rb %ld, e+1 %ld\n",
  660. X            fillsrc,filldst,repl_beginning,p_end+1);
  661. X#endif
  662. X        assert(fillsrc==p_end+1 || fillsrc==repl_beginning);
  663. X        assert(filldst==p_end+1 || filldst==repl_beginning);
  664. X    }
  665. X    }
  666. X    else {                /* normal diff--fake it up */
  667. X    char hunk_type;
  668. X    Reg3 int i;
  669. X    LINENUM min, max;
  670. X    long line_beginning = ftell(pfp);
  671. X
  672. X    p_context = 0;
  673. X    ret = pgets(buf, sizeof buf, pfp);
  674. X    p_input_line++;
  675. X    if (ret == Nullch || !isdigit(*buf)) {
  676. X        next_intuit_at(line_beginning);
  677. X        return FALSE;
  678. X    }
  679. X    p_first = (LINENUM)atol(buf);
  680. X    for (s=buf; isdigit(*s); s++) ;
  681. X    if (*s == ',') {
  682. X        p_ptrn_lines = (LINENUM)atol(++s) - p_first + 1;
  683. X        while (isdigit(*s)) s++;
  684. X    }
  685. X    else
  686. X        p_ptrn_lines = (*s != 'a');
  687. X    hunk_type = *s;
  688. X    if (hunk_type == 'a')
  689. X        p_first++;            /* do append rather than insert */
  690. X    min = (LINENUM)atol(++s);
  691. X    for (; isdigit(*s); s++) ;
  692. X    if (*s == ',')
  693. X        max = (LINENUM)atol(++s);
  694. X    else
  695. X        max = min;
  696. X    if (hunk_type == 'd')
  697. X        min++;
  698. X    p_end = p_ptrn_lines + 1 + max - min + 1;
  699. X    if (p_end > MAXHUNKSIZE)
  700. X        fatal4("Hunk too large (%ld lines) at line %ld: %s",
  701. X          p_end, p_input_line, buf);
  702. X    while (p_end >= hunkmax)
  703. X        grow_hunkmax();
  704. X    p_newfirst = min;
  705. X    p_repl_lines = max - min + 1;
  706. X    Sprintf(buf, "*** %ld,%ld\n", p_first, p_first + p_ptrn_lines - 1);
  707. X    p_line[0] = savestr(buf);
  708. X    if (out_of_mem) {
  709. X        p_end = -1;
  710. X        return FALSE;
  711. X    }
  712. X    p_char[0] = '*';
  713. X    for (i=1; i<=p_ptrn_lines; i++) {
  714. X        ret = pgets(buf, sizeof buf, pfp);
  715. X        p_input_line++;
  716. X        if (ret == Nullch)
  717. X        fatal2("Unexpected end of file in patch at line %ld.\n",
  718. X          p_input_line);
  719. X        if (*buf != '<')
  720. X        fatal2("< expected at line %ld of patch.\n", p_input_line);
  721. X        p_line[i] = savestr(buf+2);
  722. X        if (out_of_mem) {
  723. X        p_end = i-1;
  724. X        return FALSE;
  725. X        }
  726. X        p_len[i] = strlen(p_line[i]);
  727. X        p_char[i] = '-';
  728. X    }
  729. X    if (hunk_type == 'c') {
  730. X        ret = pgets(buf, sizeof buf, pfp);
  731. X        p_input_line++;
  732. X        if (ret == Nullch)
  733. X        fatal2("Unexpected end of file in patch at line %ld.\n",
  734. X            p_input_line);
  735. X        if (*buf != '-')
  736. X        fatal2("--- expected at line %ld of patch.\n", p_input_line);
  737. X    }
  738. X    Sprintf(buf, "--- %ld,%ld\n", min, max);
  739. X    p_line[i] = savestr(buf);
  740. X    if (out_of_mem) {
  741. X        p_end = i-1;
  742. X        return FALSE;
  743. X    }
  744. X    p_char[i] = '=';
  745. X    for (i++; i<=p_end; i++) {
  746. X        ret = pgets(buf, sizeof buf, pfp);
  747. X        p_input_line++;
  748. X        if (ret == Nullch)
  749. X        fatal2("Unexpected end of file in patch at line %ld.\n",
  750. X            p_input_line);
  751. X        if (*buf != '>')
  752. X        fatal2("> expected at line %ld of patch.\n", p_input_line);
  753. X        p_line[i] = savestr(buf+2);
  754. X        if (out_of_mem) {
  755. X        p_end = i-1;
  756. X        return FALSE;
  757. X        }
  758. X        p_len[i] = strlen(p_line[i]);
  759. X        p_char[i] = '+';
  760. X    }
  761. X    }
  762. X    if (reverse)            /* backwards patch? */
  763. X    if (!pch_swap())
  764. X        say1("Not enough memory to swap next hunk!\n");
  765. X#ifdef DEBUGGING
  766. X    if (debug & 2) {
  767. X    int i;
  768. X    char special;
  769. X
  770. X    for (i=0; i <= p_end; i++) {
  771. X        if (i == p_ptrn_lines)
  772. X        special = '^';
  773. X        else
  774. X        special = ' ';
  775. X        fprintf(stderr, "%3d %c %c %s", i, p_char[i], special, p_line[i]);
  776. X        Fflush(stderr);
  777. X    }
  778. X    }
  779. X#endif
  780. X    if (p_end+1 < hunkmax)    /* paranoia reigns supreme... */
  781. X    p_char[p_end+1] = '^';  /* add a stopper for apply_hunk */
  782. X    return TRUE;
  783. X
  784. Xmalformed:
  785. X    fatal3("Malformed patch at line %ld: %s", p_input_line, buf);
  786. X        /* about as informative as "Syntax error" in C */
  787. X    return FALSE;    /* for lint */
  788. X}
  789. X
  790. X/* Input a line from the patch file, worrying about indentation. */
  791. X
  792. Xchar *
  793. Xpgets(bf,sz,fp)
  794. Xchar *bf;
  795. Xint sz;
  796. XFILE *fp;
  797. X{
  798. X    char *ret = fgets(bf, sz, fp);
  799. X    Reg1 char *s;
  800. X    Reg2 int indent = 0;
  801. X
  802. X    if (p_indent && ret != Nullch) {
  803. X    for (s=buf; indent < p_indent && (*s == ' ' || *s == '\t'); s++) {
  804. X        if (*s == '\t')
  805. X        indent += 8 - (indent % 7);
  806. X        else
  807. X        indent++;
  808. X    }
  809. X    if (buf != s)
  810. X        Strcpy(buf, s);
  811. X    }
  812. X    return ret;
  813. X}
  814. X
  815. X/* Reverse the old and new portions of the current hunk. */
  816. X
  817. Xbool
  818. Xpch_swap()
  819. X{
  820. X    char **tp_line;        /* the text of the hunk */
  821. X    short *tp_len;        /* length of each line */
  822. X    char *tp_char;        /* +, -, and ! */
  823. X    Reg1 LINENUM i;
  824. X    Reg2 LINENUM n;
  825. X    bool blankline = FALSE;
  826. X    Reg3 char *s;
  827. X
  828. X    i = p_first;
  829. X    p_first = p_newfirst;
  830. X    p_newfirst = i;
  831. X    
  832. X    /* make a scratch copy */
  833. X
  834. X    tp_line = p_line;
  835. X    tp_len = p_len;
  836. X    tp_char = p_char;
  837. X    p_line = Null(char**);    /* force set_hunkmax to allocate again */
  838. X    p_len = Null(short*);
  839. X    p_char = Nullch;
  840. X    set_hunkmax();
  841. X    if (p_line == Null(char**) || p_len == Null(short*) || p_char == Nullch) {
  842. X#ifndef lint
  843. X    if (p_line == Null(char**))
  844. X        free((char*)p_line);
  845. X    p_line = tp_line;
  846. X    if (p_len == Null(short*))
  847. X        free((char*)p_len);
  848. X    p_len = tp_len;
  849. X#endif
  850. X    if (p_char == Nullch)
  851. X        free((char*)p_char);
  852. X    p_char = tp_char;
  853. X    return FALSE;        /* not enough memory to swap hunk! */
  854. X    }
  855. X
  856. X    /* now turn the new into the old */
  857. X
  858. X    i = p_ptrn_lines + 1;
  859. X    if (tp_char[i] == '\n') {        /* account for possible blank line */
  860. X    blankline = TRUE;
  861. X    i++;
  862. X    }
  863. X    for (n=0; i <= p_end; i++,n++) {
  864. X    p_line[n] = tp_line[i];
  865. X    p_char[n] = tp_char[i];
  866. X    if (p_char[n] == '+')
  867. X        p_char[n] = '-';
  868. X    p_len[n] = tp_len[i];
  869. X    }
  870. X    if (blankline) {
  871. X    i = p_ptrn_lines + 1;
  872. X    p_line[n] = tp_line[i];
  873. X    p_char[n] = tp_char[i];
  874. X    p_len[n] = tp_len[i];
  875. X    n++;
  876. X    }
  877. X    assert(p_char[0] == '=');
  878. X    p_char[0] = '*';
  879. X    for (s=p_line[0]; *s; s++)
  880. X    if (*s == '-')
  881. X        *s = '*';
  882. X
  883. X    /* now turn the old into the new */
  884. X
  885. X    assert(tp_char[0] == '*');
  886. X    tp_char[0] = '=';
  887. X    for (s=tp_line[0]; *s; s++)
  888. X    if (*s == '*')
  889. X        *s = '-';
  890. X    for (i=0; n <= p_end; i++,n++) {
  891. X    p_line[n] = tp_line[i];
  892. X    p_char[n] = tp_char[i];
  893. X    if (p_char[n] == '-')
  894. X        p_char[n] = '+';
  895. X    p_len[n] = tp_len[i];
  896. X    }
  897. X    assert(i == p_ptrn_lines + 1);
  898. X    i = p_ptrn_lines;
  899. X    p_ptrn_lines = p_repl_lines;
  900. X    p_repl_lines = i;
  901. X#ifndef lint
  902. X    if (tp_line == Null(char**))
  903. X    free((char*)tp_line);
  904. X    if (tp_len == Null(short*))
  905. X    free((char*)tp_len);
  906. X#endif
  907. X    if (tp_char == Nullch)
  908. X    free((char*)tp_char);
  909. X    return TRUE;
  910. X}
  911. X
  912. X/* Return the specified line position in the old file of the old context. */
  913. X
  914. XLINENUM
  915. Xpch_first()
  916. X{
  917. X    return p_first;
  918. X}
  919. X
  920. X/* Return the number of lines of old context. */
  921. X
  922. XLINENUM
  923. Xpch_ptrn_lines()
  924. X{
  925. X    return p_ptrn_lines;
  926. X}
  927. X
  928. X/* Return the probable line position in the new file of the first line. */
  929. X
  930. XLINENUM
  931. Xpch_newfirst()
  932. X{
  933. X    return p_newfirst;
  934. X}
  935. X
  936. X/* Return the number of lines in the replacement text including context. */
  937. X
  938. XLINENUM
  939. Xpch_repl_lines()
  940. X{
  941. X    return p_repl_lines;
  942. X}
  943. X
  944. X/* Return the number of lines in the whole hunk. */
  945. X
  946. XLINENUM
  947. Xpch_end()
  948. X{
  949. X    return p_end;
  950. X}
  951. X
  952. X/* Return the number of context lines before the first changed line. */
  953. X
  954. XLINENUM
  955. Xpch_context()
  956. X{
  957. X    return p_context;
  958. X}
  959. X
  960. X/* Return the length of a particular patch line. */
  961. X
  962. Xshort
  963. Xpch_line_len(line)
  964. XLINENUM line;
  965. X{
  966. X    return p_len[line];
  967. X}
  968. X
  969. X/* Return the control character (+, -, *, !, etc) for a patch line. */
  970. X
  971. Xchar
  972. Xpch_char(line)
  973. XLINENUM line;
  974. X{
  975. X    return p_char[line];
  976. X}
  977. X
  978. X/* Return a pointer to a particular patch line. */
  979. X
  980. Xchar *
  981. Xpfetch(line)
  982. XLINENUM line;
  983. X{
  984. X    return p_line[line];
  985. X}
  986. X
  987. X/* Return where in the patch file this hunk began, for error messages. */
  988. X
  989. XLINENUM
  990. Xpch_hunk_beg()
  991. X{
  992. X    return p_input_line - p_end - 1;
  993. X}
  994. X
  995. !STUFFY!FUNK!
  996. echo Extracting Configure
  997. sed >Configure <<'!STUFFY!FUNK!' -e 's/X//'
  998. X#! /bin/sh
  999. X#
  1000. X# If these # comments don't work, trim them.  Don't worry about any other
  1001. X# shell scripts, Configure will trim # comments from them for you.
  1002. X#
  1003. X# Note: if you are running ksh, be sure to say "sh Configure".
  1004. X#
  1005. X# (If you are trying to port this package to a machine without sh, I would
  1006. X# suggest you cut out the prototypical config.h from the end of Configure
  1007. X# and edit it to reflect your system.  Some packages may include samples
  1008. X# of config.h for certain machines, so you might look for one of those.)
  1009. X#
  1010. X# $Header: Configure,v 2.0 86/09/17 15:32:58 lwall Exp $
  1011. X#
  1012. X# $Log:    Configure,v $
  1013. X# Revision 2.0  86/09/17  15:32:58  lwall
  1014. X# Baseline for netwide release.
  1015. X# 
  1016. X#
  1017. X# Yes, you may rip this off to use in other distribution packages.
  1018. X#
  1019. X# (Note: this Configure script was generated automatically.  Rather than
  1020. X# working with this copy of Configure, you may wish to get metaconfig.)
  1021. X
  1022. Xdefine='define'
  1023. Xundef='/*undef'
  1024. X
  1025. Xd_eunice=''
  1026. Xeunicefix=''
  1027. Xloclist=''
  1028. Xexpr=''
  1029. Xsed=''
  1030. Xecho=''
  1031. Xcat=''
  1032. Xrm=''
  1033. Xmv=''
  1034. Xcp=''
  1035. Xtail=''
  1036. Xtr=''
  1037. Xmkdir=''
  1038. Xsort=''
  1039. Xuniq=''
  1040. Xgrep=''
  1041. Xtrylist=''
  1042. Xtest=''
  1043. Xinews=''
  1044. Xegrep=''
  1045. Xmore=''
  1046. Xpg=''
  1047. XMcc=''
  1048. Xvi=''
  1049. Xmailx=''
  1050. XLog=''
  1051. XHeader=''
  1052. Xbin=''
  1053. Xcc=''
  1054. Xcontains=''
  1055. Xcpp=''
  1056. Xd_index=''
  1057. Xd_void=''
  1058. Xiandd=''
  1059. Xlibc=''
  1060. Xmansrc=''
  1061. Xmanext=''
  1062. Xn=''
  1063. Xc=''
  1064. Xpackage=''
  1065. Xregisters=''
  1066. Xreg1=''
  1067. Xreg2=''
  1068. Xreg3=''
  1069. Xreg4=''
  1070. Xreg5=''
  1071. Xreg6=''
  1072. Xreg7=''
  1073. Xreg8=''
  1074. Xreg9=''
  1075. Xreg10=''
  1076. Xreg11=''
  1077. Xreg12=''
  1078. Xreg13=''
  1079. Xreg14=''
  1080. Xreg15=''
  1081. Xreg16=''
  1082. Xspitshell=''
  1083. Xshsharp=''
  1084. Xsharpbang=''
  1085. Xstartsh=''
  1086. XCONFIG=''
  1087. X
  1088. Xpackage=patch
  1089. X
  1090. Xecho "Beginning of configuration questions for $package kit."
  1091. X: Eunice requires " " instead of "", can you believe it
  1092. Xecho " "
  1093. X
  1094. X: sanity checks
  1095. XPATH='.:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc'
  1096. Xexport PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
  1097. X
  1098. Xif test ! -t 0; then
  1099. X    echo "Say 'sh Configure', not 'sh <Configure'"
  1100. X    exit 1
  1101. Xfi
  1102. X
  1103. X: some greps do not return status, grrr.
  1104. Xecho "grimblepritz" >grimble
  1105. Xif grep blurfldyick grimble >/dev/null 2>&1 ; then
  1106. X    contains=contains
  1107. Xelse
  1108. X    if grep grimblepritz grimble >/dev/null 2>&1 ; then
  1109. X    contains=grep
  1110. X    else
  1111. X    contains=contains
  1112. X    fi
  1113. Xfi
  1114. Xrm -f grimble
  1115. X: the following should work in any shell
  1116. Xcase "$contains" in
  1117. Xcontains*)
  1118. X    echo " "
  1119. X    echo "AGH!  Grep doesn't return a status.  Attempting remedial action."
  1120. X    cat >contains <<'EOSS'
  1121. Xgrep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
  1122. XEOSS
  1123. Xchmod 755 contains
  1124. Xesac
  1125. X
  1126. X: first determine how to suppress newline on echo command
  1127. Xecho "Checking echo to see how to suppress newlines..."
  1128. X(echo "hi there\c" ; echo " ") >.echotmp
  1129. Xif $contains c .echotmp >/dev/null 2>&1 ; then
  1130. X    echo "...using -n."
  1131. X    n='-n'
  1132. X    c=''
  1133. Xelse
  1134. X    echo "...using \\\c"
  1135. X    echo "c."
  1136. X    n=''
  1137. X    c='\c'
  1138. Xfi
  1139. Xecho $n "Type carriage return to continue.  Your cursor should be here-->$c"
  1140. Xread ans
  1141. Xrm -f .echotmp
  1142. X
  1143. X: now set up to do reads with possible shell escape
  1144. X: if this does not work on your machine, 1,$ s/. myread/read ans/
  1145. Xcat <<EOSC >myread
  1146. Xans='!'
  1147. Xwhile expr "X\$ans" : "X!" >/dev/null; do
  1148. X    read ans
  1149. X    case "\$ans" in
  1150. X    !)
  1151. X    sh
  1152. X    echo " "
  1153. X    echo $n "\$rp $c"
  1154. X    ;;
  1155. X    !*)
  1156. X    set \`expr "X\$ans" : "X!\(.*\)\$"\`
  1157. X    sh -c "\$*"
  1158. X    echo " "
  1159. X    echo $n "\$rp $c"
  1160. X    ;;
  1161. X    esac
  1162. Xdone
  1163. Xrp='Your answer:'
  1164. XEOSC
  1165. X
  1166. X: general instructions
  1167. Xcat <<EOH
  1168. XThis installation shell script will examine your system and ask you questions
  1169. Xto determine how $package and any auxiliary files should be installed.  If you
  1170. Xget stuck on a question, you may use a ! shell escape to start a subshell or
  1171. Xexecute a command.  Many of the questions will have default answers in
  1172. Xsquare brackets--typing carriage return will give you the default.
  1173. X
  1174. XOn some of the questions which ask for file or directory names you are
  1175. Xallowed to use the ~name construct to specify the login directory belonging
  1176. Xto "name", even if you don't have a shell which knows about that.  Questions
  1177. Xwhere this is allowed will be marked "(~name ok)".
  1178. XEOH
  1179. Xrp="[Type carriage return to continue]"
  1180. Xecho $n "$rp $c"
  1181. X. myread
  1182. Xcat <<EOH
  1183. XMuch effort has been expended to ensure that this shell script will run
  1184. Xon any Unix system.  If despite that it blows up on you, your best bet is
  1185. Xto edit Configure and run it again.  (Trying to install this package
  1186. Xwithout having run Configure may be well nigh impossible.)  Also, let me
  1187. X(lwall@sdcrdcf.UUCP) know how I blew it.
  1188. X
  1189. XThis installation script affects things in two ways: 1) it may do direct
  1190. Xvariable substitutions on some of the files included in this kit, and
  1191. X2) it builds a config.h file for inclusion in C programs.  You may edit
  1192. Xany of these files as the need arises after running this script.
  1193. X
  1194. XEOH
  1195. Xrp="[Type carriage return to continue]"
  1196. Xecho $n "$rp $c"
  1197. X. myread
  1198. X
  1199. X: get old answers, if there is a config file out there
  1200. Xif test -f config.sh; then
  1201. X    echo " "
  1202. X    rp="I see a config.sh file.  Did Configure make it on THIS system? [y]"
  1203. X    echo $n "$rp $c"
  1204. X    . myread
  1205. X    case "$ans" in
  1206. X    n*) echo "OK, I'll ignore it.";;
  1207. X    *)  echo "Fetching default answers from your old config.sh file..."
  1208. X        . config.sh
  1209. X    ;;
  1210. X    esac
  1211. Xfi
  1212. X
  1213. X: get list of predefined functions in a handy place
  1214. Xecho " "
  1215. Xif test -f /lib/libc.a; then
  1216. X    echo "Your C library is in /lib/libc.a.  You're normal."
  1217. X    libc=/lib/libc.a
  1218. Xelse
  1219. X    if test -f /usr/lib/libc.a; then
  1220. X    echo "Your C library is in /usr/lib/libc.a, of all places."
  1221. X    libc=/usr/lib/libc.a
  1222. X    else
  1223. X    if test -f "$libc"; then
  1224. X        echo "Your C library is in $libc, like you said before."
  1225. X    else
  1226. X        cat <<'EOM'
  1227. XI can't seem to find your C library.  I've looked for /lib/libc.a and
  1228. X/usr/lib/libc.a, but neither of those are there.  What is the full name
  1229. XEOM
  1230. X        echo $n "of your C library? $c"
  1231. X        rp='C library full name?'
  1232. X        . myread
  1233. X        libc="$ans"
  1234. X    fi
  1235. X    fi
  1236. Xfi
  1237. Xecho " "
  1238. Xecho $n "Extracting names from $libc for later perusal...$c"
  1239. Xif ar t $libc > libc.list; then
  1240. X    echo "done"
  1241. Xelse
  1242. X    echo " "
  1243. X    echo "The archiver doesn't think $libc is a reasonable library."
  1244. X    exit 1
  1245. Xfi
  1246. X
  1247. X: make some quick guesses about what we are up against
  1248. Xecho " "
  1249. Xecho $n "Hmm...  $c"
  1250. Xif $contains SIGTSTP /usr/include/signal.h >/dev/null 2>&1 ; then
  1251. X    echo "Looks kind of like a BSD system, but we'll see..."
  1252. X    echo exit 0 >bsd
  1253. X    echo exit 1 >usg
  1254. X    echo exit 1 >v7
  1255. Xelse
  1256. X    if $contains fcntl libc.list >/dev/null 2>&1 ; then
  1257. X    echo "Looks kind of like a USG system, but we'll see..."
  1258. X    echo exit 1 >bsd
  1259. X    echo exit 0 >usg
  1260. X    echo exit 1 >v7
  1261. X    else
  1262. X    echo "Looks kind of like a version 7 system, but we'll see..."
  1263. X    echo exit 1 >bsd
  1264. X    echo exit 1 >usg
  1265. X    echo exit 0 >v7
  1266. X    fi
  1267. Xfi
  1268. Xif $contains vmssystem libc.list >/dev/null 2>&1 ; then
  1269. X    cat <<'EOI'
  1270. XThere is, however, a strange, musty smell in the air that reminds me of
  1271. Xsomething...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
  1272. XEOI
  1273. X    echo "exit 0" >eunice
  1274. X    eunicefix=unixtovms
  1275. X    d_eunice="$define"
  1276. X: it so happens the Eunice I know will not run shell scripts in Unix format
  1277. Xelse
  1278. X    echo " "
  1279. X    echo "Congratulations.  You aren't running Eunice."
  1280. X    eunicefix=':'
  1281. X    d_eunice="$undef"
  1282. X    echo "exit 1" >eunice
  1283. Xfi
  1284. Xchmod 755 bsd usg v7 eunice
  1285. X$eunicefix bsd usg v7 eunice
  1286. X
  1287. X: see if sh knows # comments
  1288. Xecho " "
  1289. Xecho "Checking your sh to see if it knows about # comments..."
  1290. Xif sh -c '#' >/dev/null 2>&1 ; then
  1291. X    echo "Your sh handles # comments correctly."
  1292. X    shsharp=true
  1293. X    spitshell=cat
  1294. X    echo " "
  1295. X    echo "Okay, let's see if #! works on this system..."
  1296. X    echo "#!/bin/echo hi" > try
  1297. X    $eunicefix try
  1298. X    chmod 755 try
  1299. X    try > today
  1300. X    if test -s today; then
  1301. X    echo "It does."
  1302. X    sharpbang='#!'
  1303. X    else
  1304. X    echo "#! /bin/echo hi" > try
  1305. X    $eunicefix try
  1306. X    chmod 755 try
  1307. X    try > today
  1308. X    if test -s today; then
  1309. X        echo "It does."
  1310. X        sharpbang='#! '
  1311. X    else
  1312. X        echo "It doesn't."
  1313. X        sharpbang=': use '
  1314. X    fi
  1315. X    fi
  1316. Xelse
  1317. X    echo "Your sh doesn't grok # comments--I will strip them later on."
  1318. X    shsharp=false
  1319. X    echo "exec grep -v '^#'" >spitshell
  1320. X    chmod 755 spitshell
  1321. X    $eunicefix spitshell
  1322. X    spitshell=`pwd`/spitshell
  1323. X    echo "I presume that if # doesn't work, #! won't work either!"
  1324. X    sharpbang=': use '
  1325. Xfi
  1326. X
  1327. X: figure out how to guarantee sh startup
  1328. Xecho " "
  1329. Xecho "Checking out how to guarantee sh startup..."
  1330. Xstartsh=$sharpbang'/bin/sh'
  1331. Xecho "Let's see if '$startsh' works..."
  1332. Xcat >try <<EOSS
  1333. X$startsh
  1334. Xset abc
  1335. Xtest "$?abc" != 1
  1336. XEOSS
  1337. X
  1338. Xchmod 755 try
  1339. X$eunicefix try
  1340. Xif try; then
  1341. X    echo "Yup, it does."
  1342. Xelse
  1343. X    echo "Nope.  You may have to fix up the shell scripts to make sure sh runs them."
  1344. Xfi
  1345. Xrm -f try today
  1346. X
  1347. X: find out where common programs are
  1348. Xecho " "
  1349. Xecho "Locating common programs..."
  1350. Xpth="/usr/ucb /bin /usr/bin /usr/local /usr/local/bin /usr/lbin /etc /usr/lib"
  1351. Xcat <<EOSC >loc
  1352. X$startsh
  1353. Xthing=\$1
  1354. Xshift
  1355. Xdflt=\$1
  1356. Xshift
  1357. Xfor dir in \$*; do
  1358. X    case "\$thing" in
  1359. X    .)
  1360. X    if test -d \$dir/\$thing; then
  1361. X        echo \$dir
  1362. X        exit 0
  1363. X    fi
  1364. X    ;;
  1365. X    *)
  1366. X    if test -f \$dir/\$thing; then
  1367. X        echo \$dir/\$thing
  1368. X        exit 0
  1369. X    fi
  1370. X    ;;
  1371. X    esac
  1372. Xdone
  1373. Xecho \$dflt
  1374. Xexit 1
  1375. XEOSC
  1376. Xchmod 755 loc
  1377. X$eunicefix loc
  1378. Xloclist="
  1379. Xexpr
  1380. Xsed
  1381. Xecho
  1382. Xcat
  1383. Xrm
  1384. Xgrep
  1385. X"
  1386. Xtrylist="
  1387. Xtest
  1388. XMcc
  1389. X"
  1390. Xfor file in $loclist; do
  1391. X    xxx=`loc $file $file $pth`
  1392. X    eval $file=$xxx
  1393. X    case "$xxx" in
  1394. X    /*)
  1395. X    echo $file is in $xxx.
  1396. X    ;;
  1397. X    *)
  1398. X    echo "I don't know where $file is.  I hope it's in everyone's PATH."
  1399. X    ;;
  1400. X    esac
  1401. Xdone
  1402. Xecho " "
  1403. Xecho "Don't worry if any of the following aren't found..."
  1404. Xans=offhand
  1405. Xfor file in $trylist; do
  1406. X    xxx=`loc $file $file $pth`
  1407. X    eval $file=$xxx
  1408. X    case "$xxx" in
  1409. X    /*)
  1410. X    echo $file is in $xxx.
  1411. X    ;;
  1412. X    *)
  1413. X    echo "I don't see $file out there, $ans."
  1414. X    ans=either
  1415. X    ;;
  1416. X    esac
  1417. Xdone
  1418. Xcase "$egrep" in
  1419. Xegrep)
  1420. X    echo "Substituting grep for egrep."
  1421. X    egrep=$grep
  1422. X    ;;
  1423. Xesac
  1424. Xcase "$test" in
  1425. Xtest)
  1426. X    echo "Hopefully test is built into your sh."
  1427. X    ;;
  1428. X/bin/test)
  1429. X    echo " "
  1430. X    echo $n 'Is your "test" built into sh? [n] (OK to guess) '"$c"
  1431. X    rp='test built into sh? [n]'
  1432. X    . myread
  1433. X    case "$ans" in
  1434. X    y*) test=test ;;
  1435. X    esac
  1436. X    ;;
  1437. X*)
  1438. X    test=test
  1439. X    ;;
  1440. Xesac
  1441. Xcase "$echo" in
  1442. Xecho)
  1443. X    echo "Hopefully echo is built into your sh."
  1444. X    ;;
  1445. X/bin/echo)
  1446. X    echo " "
  1447. X    echo "Checking compatibility between /bin/echo and builtin echo (if any)..."
  1448. X    $echo $n "hi there$c" >foo1
  1449. X    echo $n "hi there$c" >foo2
  1450. X    if cmp foo1 foo2 >/dev/null 2>&1; then
  1451. X    echo "They are compatible.  In fact, they may be identical."
  1452. X    else
  1453. X    echo "They are not compatible--the echo builtin will be used."
  1454. X    echo=echo
  1455. X    fi
  1456. X    $rm -f foo1 foo2
  1457. X    ;;
  1458. X*)
  1459. X    echo=echo
  1460. X    ;;
  1461. Xesac
  1462. X
  1463. X: index or strcpy
  1464. X$echo " "
  1465. Xif $contains index libc.list >/dev/null 2>&1 ; then
  1466. X    $echo "Your system appears to use index() and rindex() rather than strchr()"
  1467. X    $echo $n "and strrchr().  Is this correct? [y] $c"
  1468. X    rp='index() rather than strchr()? [y]'
  1469. X    . myread
  1470. X    case "$ans" in
  1471. X    n*|f*) d_index="$define" ;;
  1472. X    *)     d_index="$undef" ;;
  1473. X    esac
  1474. Xelse
  1475. X    $echo "Your system appears to use strchr() and strrchr() rather than index()"
  1476. X    $echo $n "and rindex().  Is this correct? [y] $c"
  1477. X    rp='strchr() rather than index()? [y]'
  1478. X    . myread
  1479. X    case "$ans" in
  1480. X    n*|f*) d_index="$undef" ;;
  1481. X    *)     d_index="$define" ;;
  1482. X    esac
  1483. Xfi
  1484. X
  1485. X: check for void type
  1486. X$echo " "
  1487. X$echo "Checking to see if your C compiler groks the void type..."
  1488. X$cat >try.c <<'EOCP'
  1489. Xvoid main();
  1490. XEOCP
  1491. Xif cc -c try.c >/dev/null 2>&1 ; then
  1492. X    d_void="$undef"
  1493. X    $echo "Yup, it does."
  1494. Xelse
  1495. X    d_void="$define"
  1496. X    $echo "Nope, it doesn't (boo hiss).  I will substitute int."
  1497. Xfi
  1498. X$rm -f try.*
  1499. X
  1500. X: see how we invoke the C preprocessor
  1501. Xecho " "
  1502. Xecho "Checking to see how your C preprocessor is invoked..."
  1503. Xcat <<'EOT' >testcpp.c
  1504. X#define ABC abc
  1505. X#define XYZ xyz
  1506. XABC.XYZ
  1507. XEOT
  1508. Xecho 'Maybe "cc -E" will work...'
  1509. Xcc -E testcpp.c >testcpp.out 2>&1
  1510. Xif $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  1511. X    echo "Yup, it does."
  1512. X    cpp='cc -E'
  1513. Xelse
  1514. X    echo 'Nope...maybe "cc -P" will work...'
  1515. X    cc -P testcpp.c >testcpp.out 2>&1
  1516. X    if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  1517. X    echo "Yup, that does."
  1518. X    cpp='cc -P'
  1519. X    else
  1520. X    echo 'Nixed again...maybe "/lib/cpp" will work...'
  1521. X    /lib/cpp testcpp.c >testcpp.out 2>&1
  1522. X    if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  1523. X        echo "Hooray, it works!  I was beginning to wonder."
  1524. X        cpp='/lib/cpp'
  1525. X    else
  1526. X        echo 'Hmm...maybe you already told me...'
  1527. X        case "$cpp" in
  1528. X        '') ;;
  1529. X        *) $cpp testcpp.c >testcpp.out 2>&1;;
  1530. X        esac
  1531. X        if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  1532. X        echo "Hooray, you did!  I was beginning to wonder."
  1533. X        else
  1534. X        echo $n "Nope. I can't find a C preprocessor.  Name one: $c"
  1535. X        rp='Name a C preprocessor:'
  1536. X        . myread
  1537. X        cpp="$ans"
  1538. X        $cpp testcpp.c >testcpp.out 2>&1
  1539. X        if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then
  1540. X            echo "OK, that will do."
  1541. X        else
  1542. X            echo "Sorry, I can't get that to work.  Go find one."
  1543. X            exit 1
  1544. X        fi
  1545. X        fi
  1546. X    fi
  1547. X    fi
  1548. Xfi
  1549. Xrm -f testcpp.c testcpp.out
  1550. X
  1551. X: get C preprocessor symbols handy
  1552. Xecho " "
  1553. Xcat <<'EOT' >Cppsym.c
  1554. Xchar *sym[] = {
  1555. X#ifdef mc68000
  1556. X    "mc68000",
  1557. X#endif
  1558. X#ifdef sun
  1559. X    "sun",
  1560. X#endif
  1561. X#ifdef gcos
  1562. X    "gcos",
  1563. X#endif
  1564. X#ifdef unix
  1565. X    "unix",
  1566. X#endif
  1567. X#ifdef ibm
  1568. X    "ibm",
  1569. X#endif
  1570. X#ifdef gimpel
  1571. X    "gimpel",
  1572. X#endif
  1573. X#ifdef interdata
  1574. X    "interdata",
  1575. X#endif
  1576. X#ifdef tss
  1577. X    "tss",
  1578. X#endif
  1579. X#ifdef os
  1580. X    "os",
  1581. X#endif
  1582. X#ifdef mert
  1583. X    "mert",
  1584. X#endif
  1585. X#ifdef pyr
  1586. X    "pyr",
  1587. X#endif
  1588. X#ifdef vax
  1589. X    "vax",
  1590. X#endif
  1591. X#ifdef pdp11
  1592. X    "pdp11",
  1593. X#endif
  1594. X#ifdef i8086
  1595. X    "i8086",
  1596. X#endif
  1597. X#ifdef z8000
  1598. X    "z8000",
  1599. X#endif
  1600. X#ifdef 3b2
  1601. X    "3b2",
  1602. X#endif
  1603. X#ifdef 3b5
  1604. X    "3b5",
  1605. X#endif
  1606. X#ifdef 3b20
  1607. X    "3b20",
  1608. X#endif
  1609. X#ifdef 3b200
  1610. X    "3b200",
  1611. X#endif
  1612. X0};
  1613. Xmain(argc,argv)
  1614. Xint argc;
  1615. Xchar **argv;
  1616. X{
  1617. X    int i;
  1618. X
  1619. X    for (argc--,argv++; argc; argc--,argv++) {
  1620. X    for (i=0; sym[i]; i++) {
  1621. X        if (strcmp(argv[0],sym[i]) == 0)
  1622. X        exit(0);
  1623. X    }
  1624. X    }
  1625. X    exit(1);
  1626. X}
  1627. XEOT
  1628. Xecho "Your machine appears to have the following attributes:"
  1629. X$cpp Cppsym.c | sed -n -e 's/^    "\(.*\)",$/\1/p'
  1630. Xcc Cppsym.c -o Cppsym
  1631. Xrm -f Cppsym.c
  1632. X
  1633. X: see how many register declarations we want to use
  1634. Xcase "$registers" in
  1635. X'')
  1636. X    if Cppsym pdp11 i8086 z8000; then
  1637. X    dflt=3
  1638. X    else
  1639. X    if Cppsym sun mc68000; then
  1640. X        dflt=10
  1641. X    else
  1642. X        : if you have any other numbers for me, send them in
  1643. X        dflt=6
  1644. X    fi
  1645. X    fi
  1646. X    ;;
  1647. X*)  dflt=$registers ;;
  1648. Xesac
  1649. Xcat <<EOM
  1650. XDifferent C compilers on different machines pay attention to different
  1651. Xnumbers of register declarations.  About how many register declarations in
  1652. XEOM
  1653. X$echo $n "each routine does your C compiler pay attention to? (OK to guess) [$dflt] $c"
  1654. Xrp="# register declarations used? [$dflt]"
  1655. X. myread
  1656. Xcase "$ans" in
  1657. X'') ans=$dflt;;
  1658. Xesac
  1659. Xregisters=$ans
  1660. Xreg1=''
  1661. Xawk "END { for (i=1; i<=16; i++) printf \"reg%d=''\n\", i}" </dev/null >.foo
  1662. X. .foo
  1663. Xawk "END { for (i=1; i<=$registers; i++) printf \"reg%d=register\n\", i}" \
  1664. X    </dev/null >.foo
  1665. X. .foo
  1666. Xrm -f .foo
  1667. X
  1668. X: preserve RCS keywords in files with variable substitution, grrr
  1669. XLog='$Log'
  1670. XHeader='$Header'
  1671. X
  1672. X: set up shell script to do ~ expansion
  1673. Xcat >filexp <<EOSS
  1674. X$startsh
  1675. X: expand filename
  1676. Xcase "\$1" in
  1677. X~/*|~)
  1678. X    $echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
  1679. X    ;;
  1680. X~*)
  1681. X    if $test -f /bin/csh; then
  1682. X    /bin/csh -f -c "glob \$1"
  1683. X    $echo ""
  1684. X    else
  1685. X    name=\`$expr x\$1 : '..\([^/]*\)'\`
  1686. X    dir=\`$sed </etc/passwd -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}'\`
  1687. X    if $test ! -d "\$dir"; then
  1688. X        me=\`basename \$0\`
  1689. X        $echo "\$me: can't locate home directory for: \$name" >&2
  1690. X        exit 1
  1691. X    fi
  1692. X    case "\$1" in
  1693. X    */*)
  1694. X        $echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
  1695. X        ;;
  1696. X    *)
  1697. X        $echo \$dir
  1698. X        ;;
  1699. X    esac
  1700. X    fi
  1701. X    ;;
  1702. X*)
  1703. X    $echo \$1
  1704. X    ;;
  1705. Xesac
  1706. XEOSS
  1707. Xchmod 755 filexp
  1708. X$eunicefix filexp
  1709. X
  1710. X: determine where public executables go
  1711. Xcase "$bin" in
  1712. X'')
  1713. X    dflt=`loc . /bin /usr/local/bin /usr/lbin /usr/local /usr/bin`
  1714. X    ;;
  1715. X*)  dflt="$bin"
  1716. X    ;;
  1717. Xesac
  1718. Xbin='blurfl/dyick'
  1719. Xwhile $test ! -d "$bin" ; do
  1720. X    case "$bin" in
  1721. X      blurfl*) ;;
  1722. X      *) $echo "$bin does not appear to exist." ;;
  1723. X    esac
  1724. X    $echo " "
  1725. X    rp="Where do you want to put the public executables? [$dflt]"
  1726. X    $echo $n "$rp $c"
  1727. X    . myread
  1728. X    bin="$ans"
  1729. X    bin=`filexp $bin`
  1730. X    case "$bin" in
  1731. X      '') bin=$dflt ;;
  1732. X    esac
  1733. Xdone
  1734. X
  1735. X: determine where manual pages go
  1736. Xcase "$mansrc" in
  1737. X'')
  1738. X    dflt=`loc . /usr/man/man1 /usr/man/mann /usr/man/local/man1 /usr/man/u_man/man1 /usr/man/man1`
  1739. X    ;;
  1740. X*)  dflt="$mansrc"
  1741. X    ;;
  1742. Xesac
  1743. Xmansrc='blurfl/dyick'
  1744. Xwhile $test ! -d "$mansrc" ; do
  1745. X    case "$mansrc" in
  1746. X      blurfl*) ;;
  1747. X      *) $echo "$mansrc does not appear to exist." ;;
  1748. X    esac
  1749. X    $echo " "
  1750. X    rp="Where do the manual pages (source) go? [$dflt]"
  1751. X    $echo $n "$rp $c"
  1752. X    . myread
  1753. X    mansrc=`filexp "$ans"`
  1754. X    case "$mansrc" in
  1755. X      '') mansrc=$dflt ;;
  1756. X    esac
  1757. Xdone
  1758. Xcase "$mansrc" in
  1759. X*l)
  1760. X    manext=l
  1761. X    ;;
  1762. X*n)
  1763. X    manext=n
  1764. X    ;;
  1765. X*)
  1766. X    manext=1
  1767. X    ;;
  1768. Xesac
  1769. X
  1770. X: see if we need a special compiler
  1771. X$echo " "
  1772. Xif usg; then
  1773. X    case "$cc" in
  1774. X    '')
  1775. X    case "$Mcc" in
  1776. X    /*) dflt='Mcc'
  1777. X        ;;
  1778. X    *)
  1779. X        if $contains '\-M' $mansrc/cc.1 >/dev/null 2>&1 ; then
  1780. X        dflt='cc -M'
  1781. X        else
  1782. X        dflt='cc'
  1783. X        fi
  1784. X        ;;
  1785. X    esac
  1786. X    ;;
  1787. X    *)  dflt="$cc";;
  1788. X    esac
  1789. X    $cat <<'EOM'
  1790. XOn some systems the default C compiler will not resolve multiple global
  1791. Xreferences that happen to have the same name.  On some such systems the
  1792. X"Mcc" command may be used to force these to be resolved.  On other systems
  1793. Xa "cc -M" command is required.  What command will force resolution on
  1794. XEOM
  1795. X    $echo $n "this system? [$dflt] $c"
  1796. X    rp="Command to resolve multiple refs? [$dflt]"
  1797. X    . myread
  1798. X    cc="$ans"
  1799. X    case "$cc" in
  1800. X    '') cc="$dflt" ;;
  1801. X    esac
  1802. Xelse
  1803. X    $echo "Not a USG system--assuming cc can resolve multiple definitions."
  1804. X    cc=cc
  1805. Xfi
  1806. X
  1807. X: see if we should throw a -i into the Makefile
  1808. X$echo " "
  1809. Xif Cppsym pdp11 i8086 z8000; then
  1810. X    if $contains '\-i' $mansrc/cc.1 >/dev/null 2>&1 ; then
  1811. X    rp="Your system appears to have separate I and D space.  Is this true? [y]"
  1812. X    $echo $n "$rp $c"
  1813. X    . myread
  1814. X    case "$ans" in
  1815. X        n*|f*) iandd='' ;;
  1816. X        *)     iandd='-i' ;;
  1817. X    esac
  1818. X    else
  1819. X    $echo "Your system appears to NOT have separate I and D space."
  1820. X    $echo $n "Is this correct? [y] $c"
  1821. X    rp='No separate I and D.  Correct? [y]'
  1822. X    . myread
  1823. X    case "$ans" in
  1824. X        n*|f*) iandd='-i' ;;
  1825. X        *)     iandd='' ;;
  1826. X    esac
  1827. X    fi
  1828. Xelse
  1829. X    $echo $n "Does your machine have separate I and D space? [n] $c"
  1830. X    . myread
  1831. X    case "$ans" in
  1832. X    y*)    iandd='-i' ;;
  1833. X    *)     iandd='' ;;
  1834. X    esac
  1835. Xfi
  1836. X
  1837. X$echo " "
  1838. X$echo "End of configuration questions."
  1839. X$echo " "
  1840. X
  1841. X: create config.sh file
  1842. X$echo " "
  1843. X$echo "Creating config.sh..."
  1844. X$spitshell <<EOT >config.sh
  1845. X$startsh
  1846. X# config.sh
  1847. X# This file was produced by running the Configure script.
  1848. X
  1849. Xd_eunice='$d_eunice'
  1850. Xeunicefix='$eunicefix'
  1851. Xloclist='$loclist'
  1852. Xexpr='$expr'
  1853. Xsed='$sed'
  1854. Xecho='$echo'
  1855. Xcat='$cat'
  1856. Xrm='$rm'
  1857. Xmv='$mv'
  1858. Xcp='$cp'
  1859. Xtail='$tail'
  1860. Xtr='$tr'
  1861. Xmkdir='$mkdir'
  1862. Xsort='$sort'
  1863. Xuniq='$uniq'
  1864. Xgrep='$grep'
  1865. Xtrylist='$trylist'
  1866. Xtest='$test'
  1867. Xinews='$inews'
  1868. Xegrep='$egrep'
  1869. Xmore='$more'
  1870. Xpg='$pg'
  1871. XMcc='$Mcc'
  1872. Xvi='$vi'
  1873. Xmailx='$mailx'
  1874. XLog='$Log'
  1875. XHeader='$Header'
  1876. Xbin='$bin'
  1877. Xcc='$cc'
  1878. Xcontains='$contains'
  1879. Xcpp='$cpp'
  1880. Xd_index='$d_index'
  1881. Xd_void='$d_void'
  1882. Xiandd='$iandd'
  1883. Xlibc='$libc'
  1884. Xmansrc='$mansrc'
  1885. Xmanext='$manext'
  1886. Xn='$n'
  1887. Xc='$c'
  1888. Xpackage='$package'
  1889. Xregisters='$registers'
  1890. Xreg1='$reg1'
  1891. Xreg2='$reg2'
  1892. Xreg3='$reg3'
  1893. Xreg4='$reg4'
  1894. Xreg5='$reg5'
  1895. Xreg6='$reg6'
  1896. Xreg7='$reg7'
  1897. Xreg8='$reg8'
  1898. Xreg9='$reg9'
  1899. Xreg10='$reg10'
  1900. Xreg11='$reg11'
  1901. Xreg12='$reg12'
  1902. Xreg13='$reg13'
  1903. Xreg14='$reg14'
  1904. Xreg15='$reg15'
  1905. Xreg16='$reg16'
  1906. Xspitshell='$spitshell'
  1907. Xshsharp='$shsharp'
  1908. Xsharpbang='$sharpbang'
  1909. Xstartsh='$startsh'
  1910. XCONFIG=true
  1911. XEOT
  1912. X: create config.h file
  1913. X$echo " "
  1914. X$echo "Creating config.h..."
  1915. X$cat <<EOT >config.h
  1916. X/* config.h
  1917. X * This file was produced by running the Configure script.
  1918. X * Feel free to modify any of this as the need arises.
  1919. X */
  1920. X
  1921. X
  1922. X#$d_eunice    EUNICE        /* no file linking? */
  1923. X#$d_eunice    VMS        /* other assorted ickies? */
  1924. X
  1925. X#$d_index    index strchr    /* cultural */
  1926. X#$d_index    rindex strrchr    /*  differences? */
  1927. X
  1928. X#$d_void    void int    /* is void to be avoided? */
  1929. X
  1930. X/* How many register declarations are paid attention to? */
  1931. X
  1932. X#define Reg1 $reg1        /**/
  1933. X#define Reg2 $reg2        /**/
  1934. X#define Reg3 $reg3        /**/
  1935. X#define Reg4 $reg4        /**/
  1936. X#define Reg5 $reg5        /**/
  1937. X#define Reg6 $reg6        /**/
  1938. X#define Reg7 $reg7        /**/
  1939. X#define Reg8 $reg8        /**/
  1940. X#define Reg9 $reg9        /**/
  1941. X#define Reg10 $reg10        /**/
  1942. X#define Reg11 $reg11        /**/
  1943. X#define Reg12 $reg12        /**/
  1944. X#define Reg13 $reg13        /**/
  1945. X#define Reg14 $reg14        /**/
  1946. X#define Reg15 $reg15        /**/
  1947. X#define Reg16 $reg16        /**/
  1948. X
  1949. XEOT
  1950. XCONFIG=true
  1951. X
  1952. Xif $contains '\.SH' MANIFEST >/dev/null 2>&1; then
  1953. X    $echo " "
  1954. X    $echo "Doing variable substitutions on .SH files..."
  1955. X    set `$grep <MANIFEST '\.SH' | awk '{print $1}'`
  1956. X    for file in $*; do
  1957. X    case "$file" in
  1958. X    */*)
  1959. X        dir=`$expr X$file : 'X\(.*\)/'`
  1960. X        file=`$expr X$file : 'X.*/\(.*\)'`
  1961. X        (cd $dir && . $file)
  1962. X        ;;
  1963. X    *)
  1964. X        . $file
  1965. X        ;;
  1966. X    esac
  1967. X    done
  1968. Xfi
  1969. X
  1970. Xif $contains '^depend:' Makefile >/dev/null 2>&1; then
  1971. X    $echo " "
  1972. X    $echo 'Now you need to generate make dependencies by running "make depend".'
  1973. X    $echo 'You might prefer to run it in background: "make depend > makedepend.out &"'
  1974. X    $echo $n "Would you like me to run it for you (it takes quite a while)? [n] $c" 
  1975. X    rp="Run make depend now? [n]"
  1976. X    . myread
  1977. X    case "$ans" in
  1978. X    y*) make depend;;
  1979. X    esac
  1980. Xfi
  1981. X
  1982. X$rm -f libc.list kit*isdone bsd usg v7 eunice loc Cppsym
  1983. X
  1984. Xif test -f Makefile; then
  1985. X    $echo " "
  1986. X    $echo "Now you must run a make."
  1987. Xelse
  1988. X    $echo "Done."
  1989. Xfi
  1990. X: end of Configure
  1991. !STUFFY!FUNK!
  1992. echo Extracting util.h
  1993. sed >util.h <<'!STUFFY!FUNK!' -e 's/X//'
  1994. X/* $Header: util.h,v 2.0 86/09/17 15:40:06 lwall Exp $
  1995. X *
  1996. X * $Log:    util.h,v $
  1997. X * Revision 2.0  86/09/17  15:40:06  lwall
  1998. X * Baseline for netwide release.
  1999. X * 
  2000. X */
  2001. X
  2002. X/* and for those machine that can't handle a variable argument list */
  2003. X
  2004. X#ifdef CANVARARG
  2005. X
  2006. X#define say1 say
  2007. X#define say2 say
  2008. X#define say3 say
  2009. X#define say4 say
  2010. X#define ask1 ask
  2011. X#define ask2 ask
  2012. X#define ask3 ask
  2013. X#define ask4 ask
  2014. X#define fatal1 fatal
  2015. X#define fatal2 fatal
  2016. X#define fatal3 fatal
  2017. X#define fatal4 fatal
  2018. X
  2019. X#else /* hope they allow multi-line macro actual arguments */
  2020. X
  2021. X#ifdef lint
  2022. X
  2023. X#define say1(a) say(a, 0, 0, 0)
  2024. X#define say2(a,b) say(a, (b)==(b), 0, 0)
  2025. X#define say3(a,b,c) say(a, (b)==(b), (c)==(c), 0)
  2026. X#define say4(a,b,c,d) say(a, (b)==(b), (c)==(c), (d)==(d))
  2027. X#define ask1(a) ask(a, 0, 0, 0)
  2028. X#define ask2(a,b) ask(a, (b)==(b), 0, 0)
  2029. X#define ask3(a,b,c) ask(a, (b)==(b), (c)==(c), 0)
  2030. X#define ask4(a,b,c,d) ask(a, (b)==(b), (c)==(c), (d)==(d))
  2031. X#define fatal1(a) fatal(a, 0, 0, 0)
  2032. X#define fatal2(a,b) fatal(a, (b)==(b), 0, 0)
  2033. X#define fatal3(a,b,c) fatal(a, (b)==(b), (c)==(c), 0)
  2034. X#define fatal4(a,b,c,d) fatal(a, (b)==(b), (c)==(c), (d)==(d))
  2035. X
  2036. X#else /* lint */
  2037. X    /* if this doesn't work, try defining CANVARARG above */
  2038. X#define say1(a) say(a, Nullch, Nullch, Nullch)
  2039. X#define say2(a,b) say(a, b, Nullch, Nullch)
  2040. X#define say3(a,b,c) say(a, b, c, Nullch)
  2041. X#define say4 say
  2042. X#define ask1(a) ask(a, Nullch, Nullch, Nullch)
  2043. X#define ask2(a,b) ask(a, b, Nullch, Nullch)
  2044. X#define ask3(a,b,c) ask(a, b, c, Nullch)
  2045. X#define ask4 ask
  2046. X#define fatal1(a) fatal(a, Nullch, Nullch, Nullch)
  2047. X#define fatal2(a,b) fatal(a, b, Nullch, Nullch)
  2048. X#define fatal3(a,b,c) fatal(a, b, c, Nullch)
  2049. X#define fatal4 fatal
  2050. X
  2051. X#endif /* lint */
  2052. X
  2053. X/* if neither of the above work, join all multi-line macro calls. */
  2054. X#endif
  2055. X
  2056. XEXT char serrbuf[BUFSIZ];        /* buffer for stderr */
  2057. X
  2058. Xchar *fetchname();
  2059. Xint move_file();
  2060. Xvoid copy_file();
  2061. Xvoid say();
  2062. Xvoid fatal();
  2063. Xvoid ask();
  2064. Xchar *savestr();
  2065. Xvoid set_signals();
  2066. Xvoid ignore_signals();
  2067. Xvoid makedirs();
  2068. !STUFFY!FUNK!
  2069. echo Extracting EXTERN.h
  2070. sed >EXTERN.h <<'!STUFFY!FUNK!' -e 's/X//'
  2071. X/* $Header: EXTERN.h,v 2.0 86/09/17 15:35:37 lwall Exp $
  2072. X *
  2073. X * $Log:    EXTERN.h,v $
  2074. X * Revision 2.0  86/09/17  15:35:37  lwall
  2075. X * Baseline for netwide release.
  2076. X * 
  2077. X */
  2078. X
  2079. X#undef EXT
  2080. X#define EXT extern
  2081. X
  2082. X#undef INIT
  2083. X#define INIT(x)
  2084. X
  2085. X#undef DOINIT
  2086. !STUFFY!FUNK!
  2087. echo ""
  2088. echo "End of kit 1 (of 3)"
  2089. cat /dev/null >kit1isdone
  2090. config=true
  2091. for iskit in 1 2 3; do
  2092.     if test -f kit${iskit}isdone; then
  2093.     echo "You have run kit ${iskit}."
  2094.     else
  2095.     echo "You still need to run kit ${iskit}."
  2096.     config=false
  2097.     fi
  2098. done
  2099. case $config in
  2100.     true)
  2101.     echo "You have run all your kits.  Please read README and then type Configure."
  2102.     chmod 755 Configure
  2103.     ;;
  2104. esac
  2105. : I do not append .signature, but someone might mail this.
  2106. exit
  2107.