home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / rcs567s.zip / rcs / src / rcsgen.c < prev    next >
C/C++ Source or Header  |  1994-03-17  |  17KB  |  676 lines

  1. /* Generate RCS revisions.  */
  2.  
  3. /* Copyright 1982, 1988, 1989 Walter Tichy
  4.    Copyright 1990, 1991, 1992, 1993, 1994 Paul Eggert
  5.    Distributed under license by the Free Software Foundation, Inc.
  6.  
  7. This file is part of RCS.
  8.  
  9. RCS is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2, or (at your option)
  12. any later version.
  13.  
  14. RCS is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with RCS; see the file COPYING.  If not, write to
  21. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Report problems and direct all questions to:
  24.  
  25.     rcs-bugs@cs.purdue.edu
  26.  
  27. */
  28.  
  29. /*
  30.  * $Log: rcsgen.c,v $
  31.  * Revision 5.14  1994/03/17 14:05:48  eggert
  32.  * Work around SVR4 stdio performance bug.
  33.  * Flush stderr after prompt.  Remove lint.
  34.  *
  35.  * Revision 5.13  1993/11/03 17:42:27  eggert
  36.  * Don't discard ignored phrases.  Improve quality of diagnostics.
  37.  *
  38.  * Revision 5.12  1992/07/28  16:12:44  eggert
  39.  * Statement macro names now end in _.
  40.  * Be consistent about pathnames vs filenames.
  41.  *
  42.  * Revision 5.11  1992/01/24  18:44:19  eggert
  43.  * Move put routines here from rcssyn.c.
  44.  * Add support for bad_creat0.
  45.  *
  46.  * Revision 5.10  1991/10/07  17:32:46  eggert
  47.  * Fix log bugs, e.g. ci -t/dev/null when has_mmap.
  48.  *
  49.  * Revision 5.9  1991/09/10  22:15:46  eggert
  50.  * Fix test for redirected stdin.
  51.  *
  52.  * Revision 5.8  1991/08/19  03:13:55  eggert
  53.  * Add piece tables.  Tune.
  54.  *
  55.  * Revision 5.7  1991/04/21  11:58:24  eggert
  56.  * Add MS-DOS support.
  57.  *
  58.  * Revision 5.6  1990/12/27  19:54:26  eggert
  59.  * Fix bug: rcs -t inserted \n, making RCS file grow.
  60.  *
  61.  * Revision 5.5  1990/12/04  05:18:45  eggert
  62.  * Use -I for prompts and -q for diagnostics.
  63.  *
  64.  * Revision 5.4  1990/11/01  05:03:47  eggert
  65.  * Add -I and new -t behavior.  Permit arbitrary data in logs.
  66.  *
  67.  * Revision 5.3  1990/09/21  06:12:43  hammer
  68.  * made putdesc() treat stdin the same whether or not it was from a terminal
  69.  * by making it recognize that a single '.' was then end of the
  70.  * description always
  71.  *
  72.  * Revision 5.2  1990/09/04  08:02:25  eggert
  73.  * Fix `co -p1.1 -ko' bug.  Standardize yes-or-no procedure.
  74.  *
  75.  * Revision 5.1  1990/08/29  07:14:01  eggert
  76.  * Clean old log messages too.
  77.  *
  78.  * Revision 5.0  1990/08/22  08:12:52  eggert
  79.  * Remove compile-time limits; use malloc instead.
  80.  * Ansify and Posixate.
  81.  *
  82.  * Revision 4.7  89/05/01  15:12:49  narten
  83.  * changed copyright header to reflect current distribution rules
  84.  * 
  85.  * Revision 4.6  88/08/28  14:59:10  eggert
  86.  * Shrink stdio code size; allow cc -R; remove lint; isatty() -> ttystdin()
  87.  * 
  88.  * Revision 4.5  87/12/18  11:43:25  narten
  89.  * additional lint cleanups, and a bug fix from the 4.3BSD version that
  90.  * keeps "ci" from sticking a '\377' into the description if you run it
  91.  * with a zero-length file as the description. (Guy Harris)
  92.  * 
  93.  * Revision 4.4  87/10/18  10:35:10  narten
  94.  * Updating version numbers. Changes relative to 1.1 actually relative to
  95.  * 4.2
  96.  * 
  97.  * Revision 1.3  87/09/24  13:59:51  narten
  98.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  99.  * warnings)
  100.  * 
  101.  * Revision 1.2  87/03/27  14:22:27  jenkins
  102.  * Port to suns
  103.  * 
  104.  * Revision 4.2  83/12/02  23:01:39  wft
  105.  * merged 4.1 and 3.3.1.1 (clearerr(stdin)).
  106.  * 
  107.  * Revision 4.1  83/05/10  16:03:33  wft
  108.  * Changed putamin() to abort if trying to reread redirected stdin.
  109.  * Fixed getdesc() to output a prompt on initial newline.
  110.  * 
  111.  * Revision 3.3.1.1  83/10/19  04:21:51  lepreau
  112.  * Added clearerr(stdin) for re-reading description from stdin.
  113.  * 
  114.  * Revision 3.3  82/11/28  21:36:49  wft
  115.  * 4.2 prerelease
  116.  * 
  117.  * Revision 3.3  82/11/28  21:36:49  wft
  118.  * Replaced ferror() followed by fclose() with ffclose().
  119.  * Putdesc() now suppresses the prompts if stdin
  120.  * is not a terminal. A pointer to the current log message is now
  121.  * inserted into the corresponding delta, rather than leaving it in a
  122.  * global variable.
  123.  *
  124.  * Revision 3.2  82/10/18  21:11:26  wft
  125.  * I added checks for write errors during editing, and improved
  126.  * the prompt on putdesc().
  127.  *
  128.  * Revision 3.1  82/10/13  15:55:09  wft
  129.  * corrected type of variables assigned to by getc (char --> int)
  130.  */
  131.  
  132.  
  133.  
  134.  
  135. #include "rcsbase.h"
  136.  
  137. libId(genId, "$Id: rcsgen.c,v 5.14 1994/03/17 14:05:48 eggert Exp $")
  138.  
  139. int interactiveflag;  /* Should we act as if stdin is a tty?  */
  140. struct buf curlogbuf;  /* buffer for current log message */
  141.  
  142. enum stringwork { enter, copy, edit, expand, edit_expand };
  143.  
  144. static void putdelta P((struct hshentry const*,FILE*));
  145. static void scandeltatext P((struct hshentry*,enum stringwork,int));
  146.  
  147.  
  148.  
  149.  
  150.     char const *
  151. buildrevision(deltas, target, outfile, expandflag)
  152.     struct hshentries const *deltas;
  153.     struct hshentry *target;
  154.     FILE *outfile;
  155.     int expandflag;
  156. /* Function: Generates the revision given by target
  157.  * by retrieving all deltas given by parameter deltas and combining them.
  158.  * If outfile is set, the revision is output to it,
  159.  * otherwise written into a temporary file.
  160.  * Temporary files are allocated by maketemp().
  161.  * if expandflag is set, keyword expansion is performed.
  162.  * Return 0 if outfile is set, the name of the temporary file otherwise.
  163.  *
  164.  * Algorithm: Copy initial revision unchanged.  Then edit all revisions but
  165.  * the last one into it, alternating input and output files (resultname and
  166.  * editname). The last revision is then edited in, performing simultaneous
  167.  * keyword substitution (this saves one extra pass).
  168.  * All this simplifies if only one revision needs to be generated,
  169.  * or no keyword expansion is necessary, or if output goes to stdout.
  170.  */
  171. {
  172.     if (deltas->first == target) {
  173.                 /* only latest revision to generate */
  174.         openfcopy(outfile);
  175.         scandeltatext(target, expandflag?expand:copy, true);
  176.         if (outfile)
  177.             return 0;
  178.         else {
  179.             Ozclose(&fcopy);
  180.             return resultname;
  181.         }
  182.         } else {
  183.                 /* several revisions to generate */
  184.         /* Get initial revision without keyword expansion.  */
  185.         scandeltatext(deltas->first, enter, false);
  186.         while ((deltas=deltas->rest)->rest) {
  187.                         /* do all deltas except last one */
  188.             scandeltatext(deltas->first, edit, false);
  189.                 }
  190.         if (expandflag || outfile) {
  191.                         /* first, get to beginning of file*/
  192.             finishedit((struct hshentry*)0, outfile, false);
  193.                 }
  194.         scandeltatext(target, expandflag?edit_expand:edit, true);
  195.         finishedit(
  196.             expandflag ? target : (struct hshentry*)0,
  197.             outfile, true
  198.         );
  199.         if (outfile)
  200.             return 0;
  201.         Ozclose(&fcopy);
  202.         return resultname;
  203.         }
  204. }
  205.  
  206.  
  207.  
  208.     static void
  209. scandeltatext(delta, func, needlog)
  210.     struct hshentry *delta;
  211.     enum stringwork func;
  212.     int needlog;
  213. /* Function: Scans delta text nodes up to and including the one given
  214.  * by delta. For the one given by delta, the log message is saved into
  215.  * delta->log if needlog is set; func specifies how to handle the text.
  216.  * Similarly, if needlog, delta->igtext is set to the ignored phrases.
  217.  * Assumes the initial lexeme must be read in first.
  218.  * Does not advance nexttok after it is finished.
  219.  */
  220. {
  221.     struct hshentry const *nextdelta;
  222.     struct cbuf cb;
  223.  
  224.         for (;;) {
  225.         if (eoflex())
  226.             fatserror("can't find delta for revision %s", delta->num);
  227.                 nextlex();
  228.                 if (!(nextdelta=getnum())) {
  229.             fatserror("delta number corrupted");
  230.                 }
  231.         getkeystring(Klog);
  232.         if (needlog && delta==nextdelta) {
  233.             cb = savestring(&curlogbuf);
  234.             delta->log = cleanlogmsg(curlogbuf.string, cb.size);
  235.             nextlex();
  236.             delta->igtext = getphrases(Ktext);
  237.                 } else {readstring();
  238.             ignorephrases(Ktext);
  239.                 }
  240.         getkeystring(Ktext);
  241.  
  242.         if (delta==nextdelta)
  243.             break;
  244.         readstring(); /* skip over it */
  245.  
  246.     }
  247.     switch (func) {
  248.         case enter: enterstring(); break;
  249.         case copy: copystring(); break;
  250.         case expand: xpandstring(delta); break;
  251.         case edit: editstring((struct hshentry *)0); break;
  252.         case edit_expand: editstring(delta); break;
  253.     }
  254. }
  255.  
  256.     struct cbuf
  257. cleanlogmsg(m, s)
  258.     char *m;
  259.     size_t s;
  260. {
  261.     register char *t = m;
  262.     register char const *f = t;
  263.     struct cbuf r;
  264.     while (s) {
  265.         --s;
  266.         if ((*t++ = *f++) == '\n')
  267.         while (m < --t)
  268.             if (t[-1]!=' ' && t[-1]!='\t') {
  269.             *t++ = '\n';
  270.             break;
  271.             }
  272.     }
  273.     while (m < t  &&  (t[-1]==' ' || t[-1]=='\t' || t[-1]=='\n'))
  274.         --t;
  275.     r.string = m;
  276.     r.size = t - m;
  277.     return r;
  278. }
  279.  
  280.  
  281. int ttystdin()
  282. {
  283.     static int initialized;
  284.     if (!initialized) {
  285.         if (!interactiveflag)
  286.             interactiveflag = isatty(STDIN_FILENO);
  287.         initialized = true;
  288.     }
  289.     return interactiveflag;
  290. }
  291.  
  292.     int
  293. getcstdin()
  294. {
  295.     register FILE *in;
  296.     register int c;
  297.  
  298.     in = stdin;
  299.     if (feof(in) && ttystdin())
  300.         clearerr(in);
  301.     c = getc(in);
  302.     if (c == EOF) {
  303.         testIerror(in);
  304.         if (feof(in) && ttystdin())
  305.             afputc('\n',stderr);
  306.     }
  307.     return c;
  308. }
  309.  
  310. #if has_prototypes
  311.     int
  312. yesorno(int default_answer, char const *question, ...)
  313. #else
  314.         /*VARARGS2*/ int
  315.     yesorno(default_answer, question, va_alist)
  316.         int default_answer; char const *question; va_dcl
  317. #endif
  318. {
  319.     va_list args;
  320.     register int c, r;
  321.     if (!quietflag && ttystdin()) {
  322.         oflush();
  323.         vararg_start(args, question);
  324.         fvfprintf(stderr, question, args);
  325.         va_end(args);
  326.         eflush();
  327.         r = c = getcstdin();
  328.         while (c!='\n' && !feof(stdin))
  329.             c = getcstdin();
  330.         if (r=='y' || r=='Y')
  331.             return true;
  332.         if (r=='n' || r=='N')
  333.             return false;
  334.     }
  335.     return default_answer;
  336. }
  337.  
  338.  
  339.     void
  340. putdesc(textflag, textfile)
  341.     int textflag;
  342.     char *textfile;
  343. /* Function: puts the descriptive text into file frewrite.
  344.  * if finptr && !textflag, the text is copied from the old description.
  345.  * Otherwise, if textfile, the text is read from that
  346.  * file, or from stdin, if !textfile.
  347.  * A textfile with a leading '-' is treated as a string, not a pathname.
  348.  * If finptr, the old descriptive text is discarded.
  349.  * Always clears foutptr.
  350.  */
  351. {
  352.     static struct buf desc;
  353.     static struct cbuf desclean;
  354.  
  355.     register FILE *txt;
  356.     register int c;
  357.     register FILE * frew;
  358.     register char *p;
  359.     register size_t s;
  360.     char const *plim;
  361.  
  362.     frew = frewrite;
  363.     if (finptr && !textflag) {
  364.                 /* copy old description */
  365.         aprintf(frew, "\n\n%s%c", Kdesc, nextc);
  366.         foutptr = frewrite;
  367.         getdesc(false);
  368.         foutptr = 0;
  369.         } else {
  370.         foutptr = 0;
  371.                 /* get new description */
  372.         if (finptr) {
  373.                         /*skip old description*/
  374.             getdesc(false);
  375.                 }
  376.         aprintf(frew,"\n\n%s\n%c",Kdesc,SDELIM);
  377.         if (!textfile)
  378.             desclean = getsstdin(
  379.                 "t-", "description",
  380.                 "NOTE: This is NOT the log message!\n", &desc
  381.             );
  382.         else if (!desclean.string) {
  383.             if (*textfile == '-') {
  384.                 p = textfile + 1;
  385.                 s = strlen(p);
  386.             } else {
  387.                 if (!(txt = fopen(textfile, "r")))
  388.                     efaterror(textfile);
  389.                 bufalloc(&desc, 1);
  390.                 p = desc.string;
  391.                 plim = p + desc.size;
  392.                 for (;;) {
  393.                     if ((c=getc(txt)) == EOF) {
  394.                         testIerror(txt);
  395.                         if (feof(txt))
  396.                             break;
  397.                     }
  398.                     if (plim <= p)
  399.                         p = bufenlarge(&desc, &plim);
  400.                     *p++ = c;
  401.                 }
  402.                 if (fclose(txt) != 0)
  403.                     Ierror();
  404.                 s = p - desc.string;
  405.                 p = desc.string;
  406.             }
  407.             desclean = cleanlogmsg(p, s);
  408.         }
  409.         putstring(frew, false, desclean, true);
  410.         aputc_('\n', frew)
  411.         }
  412. }
  413.  
  414.     struct cbuf
  415. getsstdin(option, name, note, buf)
  416.     char const *option, *name, *note;
  417.     struct buf *buf;
  418. {
  419.     register int c;
  420.     register char *p;
  421.     register size_t i;
  422.     register int tty = ttystdin();
  423.  
  424.     if (tty) {
  425.         aprintf(stderr,
  426.         "enter %s, terminated with single '.' or end of file:\n%s>> ",
  427.         name, note
  428.         );
  429.         eflush();
  430.     } else if (feof(stdin))
  431.         rcsfaterror("can't reread redirected stdin for %s; use -%s<%s>",
  432.         name, option, name
  433.         );
  434.     
  435.     for (
  436.        i = 0,  p = 0;
  437.        c = getcstdin(),  !feof(stdin);
  438.        bufrealloc(buf, i+1),  p = buf->string,  p[i++] = c
  439.     )
  440.         if (c == '\n')
  441.             if (i  &&  p[i-1]=='.'  &&  (i==1 || p[i-2]=='\n')) {
  442.                 /* Remove trailing '.'.  */
  443.                 --i;
  444.                 break;
  445.             } else if (tty) {
  446.                 aputs(">> ", stderr);
  447.                 eflush();
  448.             }
  449.     return cleanlogmsg(p, i);
  450. }
  451.  
  452.  
  453.     void
  454. putadmin()
  455. /* Output the admin node.  */
  456. {
  457.     register FILE *fout;
  458.     struct assoc const *curassoc;
  459.     struct lock const *curlock;
  460.     struct access const *curaccess;
  461.  
  462.     if (!(fout = frewrite)) {
  463. #        if bad_creat0
  464.             ORCSclose();
  465.             fout = fopen(makedirtemp(0), FOPEN_W);
  466. #        else
  467.             int fo = fdlock;
  468.             fdlock = -1;
  469.             fout = fdopen(fo, FOPEN_W);
  470. #        endif
  471.  
  472.         if (!(frewrite = fout))
  473.             efaterror(RCSname);
  474.     }
  475.  
  476.     /*
  477.     * Output the first character with putc, not printf.
  478.     * Otherwise, an SVR4 stdio bug buffers output inefficiently.
  479.     */
  480.     aputc_(*Khead, fout)
  481.     aprintf(fout, "%s\t%s;\n", Khead + 1, Head?Head->num:"");
  482.     if (Dbranch && VERSION(4)<=RCSversion)
  483.         aprintf(fout, "%s\t%s;\n", Kbranch, Dbranch);
  484.  
  485.     aputs(Kaccess, fout);
  486.     curaccess = AccessList;
  487.     while (curaccess) {
  488.            aprintf(fout, "\n\t%s", curaccess->login);
  489.            curaccess = curaccess->nextaccess;
  490.     }
  491.     aprintf(fout, ";\n%s", Ksymbols);
  492.     curassoc = Symbols;
  493.     while (curassoc) {
  494.            aprintf(fout, "\n\t%s:%s", curassoc->symbol, curassoc->num);
  495.            curassoc = curassoc->nextassoc;
  496.     }
  497.     aprintf(fout, ";\n%s", Klocks);
  498.     curlock = Locks;
  499.     while (curlock) {
  500.            aprintf(fout, "\n\t%s:%s", curlock->login, curlock->delta->num);
  501.            curlock = curlock->nextlock;
  502.     }
  503.     if (StrictLocks) aprintf(fout, "; %s", Kstrict);
  504.     aprintf(fout, ";\n");
  505.     if (Comment.size) {
  506.         aprintf(fout, "%s\t", Kcomment);
  507.         putstring(fout, true, Comment, false);
  508.         aprintf(fout, ";\n");
  509.     }
  510.     if (Expand != KEYVAL_EXPAND)
  511.         aprintf(fout, "%s\t%c%s%c;\n",
  512.             Kexpand, SDELIM, expand_names[Expand], SDELIM
  513.         );
  514.     awrite(Ignored.string, Ignored.size, fout);
  515.     aputc_('\n', fout)
  516. }
  517.  
  518.  
  519.     static void
  520. putdelta(node, fout)
  521.     register struct hshentry const *node;
  522.     register FILE * fout;
  523. /* Output the delta NODE to FOUT.  */
  524. {
  525.     struct branchhead const *nextbranch;
  526.  
  527.     if (!node) return;
  528.  
  529.     aprintf(fout, "\n%s\n%s\t%s;\t%s %s;\t%s %s;\nbranches",
  530.         node->num,
  531.         Kdate, node->date,
  532.         Kauthor, node->author,
  533.         Kstate, node->state?node->state:""
  534.     );
  535.     nextbranch = node->branches;
  536.     while (nextbranch) {
  537.            aprintf(fout, "\n\t%s", nextbranch->hsh->num);
  538.            nextbranch = nextbranch->nextbranch;
  539.     }
  540.  
  541.     aprintf(fout, ";\n%s\t%s;\n", Knext, node->next?node->next->num:"");
  542.     awrite(node->ig.string, node->ig.size, fout);
  543. }
  544.  
  545.  
  546.     void
  547. puttree(root, fout)
  548.     struct hshentry const *root;
  549.     register FILE *fout;
  550. /* Output the delta tree with base ROOT in preorder to FOUT.  */
  551. {
  552.     struct branchhead const *nextbranch;
  553.  
  554.     if (!root) return;
  555.  
  556.     if (root->selector)
  557.         putdelta(root, fout);
  558.  
  559.     puttree(root->next, fout);
  560.  
  561.     nextbranch = root->branches;
  562.     while (nextbranch) {
  563.          puttree(nextbranch->hsh, fout);
  564.          nextbranch = nextbranch->nextbranch;
  565.     }
  566. }
  567.  
  568.  
  569.     int
  570. putdtext(delta, srcname, fout, diffmt)
  571.     struct hshentry const *delta;
  572.     char const *srcname;
  573.     FILE *fout;
  574.     int diffmt;
  575. /*
  576.  * Output a deltatext node with delta number DELTA->num, log message DELTA->log,
  577.  * ignored phrases DELTA->igtext and text SRCNAME to FOUT.
  578.  * Double up all SDELIMs in both the log and the text.
  579.  * Make sure the log message ends in \n.
  580.  * Return false on error.
  581.  * If DIFFMT, also check that the text is valid diff -n output.
  582.  */
  583. {
  584.     RILE *fin;
  585.     if (!(fin = Iopen(srcname, "r", (struct stat*)0))) {
  586.         eerror(srcname);
  587.         return false;
  588.     }
  589.     putdftext(delta, fin, fout, diffmt);
  590.     Ifclose(fin);
  591.     return true;
  592. }
  593.  
  594.     void
  595. putstring(out, delim, s, log)
  596.     register FILE *out;
  597.     struct cbuf s;
  598.     int delim, log;
  599. /*
  600.  * Output to OUT one SDELIM if DELIM, then the string S with SDELIMs doubled.
  601.  * If LOG is set then S is a log string; append a newline if S is nonempty.
  602.  */
  603. {
  604.     register char const *sp;
  605.     register size_t ss;
  606.  
  607.     if (delim)
  608.         aputc_(SDELIM, out)
  609.     sp = s.string;
  610.     for (ss = s.size;  ss;  --ss) {
  611.         if (*sp == SDELIM)
  612.             aputc_(SDELIM, out)
  613.         aputc_(*sp++, out)
  614.     }
  615.     if (s.size && log)
  616.         aputc_('\n', out)
  617.     aputc_(SDELIM, out)
  618. }
  619.  
  620.     void
  621. putdftext(delta, finfile, foutfile, diffmt)
  622.     struct hshentry const *delta;
  623.     RILE *finfile;
  624.     FILE *foutfile;
  625.     int diffmt;
  626. /* like putdtext(), except the source file is already open */
  627. {
  628.     declarecache;
  629.     register FILE *fout;
  630.     register int c;
  631.     register RILE *fin;
  632.     int ed;
  633.     struct diffcmd dc;
  634.  
  635.     fout = foutfile;
  636.     aprintf(fout, DELNUMFORM, delta->num, Klog);
  637.  
  638.     /* put log */
  639.     putstring(fout, true, delta->log, true);
  640.     aputc_('\n', fout)
  641.  
  642.     /* put ignored phrases */
  643.     awrite(delta->igtext.string, delta->igtext.size, fout);
  644.  
  645.     /* put text */
  646.     aprintf(fout, "%s\n%c", Ktext, SDELIM);
  647.  
  648.     fin = finfile;
  649.     setupcache(fin);
  650.     if (!diffmt) {
  651.         /* Copy the file */
  652.         cache(fin);
  653.         for (;;) {
  654.         cachegeteof_(c, break;)
  655.         if (c==SDELIM) aputc_(SDELIM, fout) /*double up SDELIM*/
  656.         aputc_(c, fout)
  657.         }
  658.     } else {
  659.         initdiffcmd(&dc);
  660.         while (0  <=  (ed = getdiffcmd(fin, false, fout, &dc)))
  661.         if (ed) {
  662.             cache(fin);
  663.             while (dc.nlines--)
  664.             do {
  665.                 cachegeteof_(c, { if (!dc.nlines) goto OK_EOF; unexpected_EOF(); })
  666.                 if (c == SDELIM)
  667.                 aputc_(SDELIM, fout)
  668.                 aputc_(c, fout)
  669.             } while (c != '\n');
  670.             uncache(fin);
  671.         }
  672.     }
  673.     OK_EOF:
  674.     aprintf(fout, "%c\n", SDELIM);
  675. }
  676.