Debian Codegraph @

src/commands.c

raw symbols SCIP
1 /* Command processing for GNU Make.
2 Copyright (C) 1988-2020 Free Software Foundation, Inc.
3 This file is part of GNU Make.
4
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
8 version.
9
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include "makeint.h"
18 #include "filedef.h"
19 #include "dep.h"
20 #include "variable.h"
21 #include "job.h"
22 #include "commands.h"
23 #include "expand.h"
24
25 #define FILE_LIST_SEPARATOR ' '
26
27 #ifndef HAVE_UNISTD_H
28 pid_t getpid ();
29 #endif
30
31
32 static unsigned long
33 dep_hash_1 (const void *key)
34 {
35 const struct dep *d = key;
36 return_STRING_HASH_1 (dep_name (d));
37 }
38
39 static unsigned long
40 dep_hash_2 (const void *key)
41 {
42 const struct dep *d = key;
43 return_STRING_HASH_2 (dep_name (d));
44 }
45
46 static int
47 dep_hash_cmp (const void *x, const void *y)
48 {
49 const struct dep *dx = x;
50 const struct dep *dy = y;
51 return strcmp (dep_name (dx), dep_name (dy));
52 }
53
54 /* Set FILE's automatic variables up. */
55
56 void
57 set_file_variables (struct file *file)
58 {
59 struct dep *d;
60 const char *at, *percent, *star, *less;
61
62 #ifndef NO_ARCHIVES
63 /* If the target is an archive member 'lib(member)',
64 then $@ is 'lib' and $% is 'member'. */
65
66 if (ar_name (file->name))
67 {
68 size_t len;
69 const char *cp;
70 char *p;
71
72 cp = strchr (file->name, '(');
73 p = alloca (cp - file->name + 1);
74 memcpy (p, file->name, cp - file->name);
75 p[cp - file->name] = '\0';
76 at = p;
77 len = strlen (cp + 1);
78 p = alloca (len);
79 memcpy (p, cp + 1, len - 1);
80 p[len - 1] = '\0';
81 percent = p;
82 }
83 else
84 #endif /* NO_ARCHIVES. */
85 {
86 at = file->name;
87 percent = "";
88 }
89
90 /* $* is the stem from an implicit or static pattern rule. */
91 if (file->stem == 0)
92 {
93 /* In Unix make, $* is set to the target name with
94 any suffix in the .SUFFIXES list stripped off for
95 explicit rules. We store this in the 'stem' member. */
96 const char *name;
97 size_t len;
98
99 #ifndef NO_ARCHIVES
100 if (ar_name (file->name))
101 {
102 name = strchr (file->name, '(') + 1;
103 len = strlen (name) - 1;
104 }
105 else
106 #endif
107 {
108 name = file->name;
109 len = strlen (name);
110 }
111
112 for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next)
113 {
114 size_t slen = strlen (dep_name (d));
115 if (len > slen && strneq (dep_name (d), name + (len - slen), slen))
116 {
117 file->stem = strcache_add_len (name, len - slen);
118 break;
119 }
120 }
121 if (d == 0)
122 file->stem = "";
123 }
124 star = file->stem;
125
126 /* $< is the first not order-only dependency. */
127 less = "";
128 for (d = file->deps; d != 0; d = d->next)
129 if (!d->ignore_mtime && !d->ignore_automatic_vars)
130 {
131 if (!d->need_2nd_expansion)
132 less = dep_name (d);
133 break;
134 }
135
136 if (file->cmds != 0 && file->cmds == default_file->cmds)
137 /* This file got its commands from .DEFAULT.
138 In this case $< is the same as $@. */
139 less = at;
140
141 #define DEFINE_VARIABLE(name, len, value) \
142 (void) define_variable_for_file (name,len,value,o_automatic,0,file)
143
144 /* Define the variables. */
145
146 DEFINE_VARIABLE ("<", 1, less);
147 DEFINE_VARIABLE ("*", 1, star);
148 DEFINE_VARIABLE ("@", 1, at);
149 DEFINE_VARIABLE ("%", 1, percent);
150
151 /* Compute the values for $^, $+, $?, and $|. */
152
153 {
154 static char *plus_value=0, *bar_value=0, *qmark_value=0;
155 static size_t plus_max=0, bar_max=0, qmark_max=0;
156
157 size_t qmark_len, plus_len, bar_len;
158 char *cp;
159 char *caret_value;
160 char *qp;
161 char *bp;
162 size_t len;
163
164 struct hash_table dep_hash;
165 void **slot;
166
167 /* Compute first the value for $+, which is supposed to contain
168 duplicate dependencies as they were listed in the makefile. */
169
170 plus_len = 0;
171 bar_len = 0;
172 for (d = file->deps; d != 0; d = d->next)
173 {
174 if (!d->need_2nd_expansion && !d->ignore_automatic_vars)
175 {
176 if (d->ignore_mtime)
177 bar_len += strlen (dep_name (d)) + 1;
178 else
179 plus_len += strlen (dep_name (d)) + 1;
180 }
181 }
182
183 if (bar_len == 0)
184 bar_len++;
185
186 if (plus_len == 0)
187 plus_len++;
188
189 if (plus_len > plus_max)
190 plus_value = xrealloc (plus_value, plus_max = plus_len);
191
192 cp = plus_value;
193
194 qmark_len = plus_len + 1; /* Will be this or less. */
195 for (d = file->deps; d != 0; d = d->next)
196 if (! d->ignore_mtime && ! d->need_2nd_expansion && ! d->ignore_automatic_vars)
197 {
198 const char *c = dep_name (d);
199
200 #ifndef NO_ARCHIVES
201 if (ar_name (c))
202 {
203 c = strchr (c, '(') + 1;
204 len = strlen (c) - 1;
205 }
206 else
207 #endif
208 len = strlen (c);
209
210 memcpy (cp, c, len);
211 cp += len;
212 *cp++ = FILE_LIST_SEPARATOR;
213 if (! (d->changed || always_make_flag))
214 qmark_len -= len + 1; /* Don't space in $? for this one. */
215 }
216
217 /* Kill the last space and define the variable. */
218
219 cp[cp > plus_value ? -1 : 0] = '\0';
220 DEFINE_VARIABLE ("+", 1, plus_value);
221
222 /* Compute the values for $^, $?, and $|. */
223
224 cp = caret_value = plus_value; /* Reuse the buffer; it's big enough. */
225
226 if (qmark_len > qmark_max)
227 qmark_value = xrealloc (qmark_value, qmark_max = qmark_len);
228 qp = qmark_value;
229
230 if (bar_len > bar_max)
231 bar_value = xrealloc (bar_value, bar_max = bar_len);
232 bp = bar_value;
233
234 /* Make sure that no dependencies are repeated in $^, $?, and $|. It
235 would be natural to combine the next two loops but we can't do it
236 because of a situation where we have two dep entries, the first
237 is order-only and the second is normal (see below). */
238
239 hash_init (&dep_hash, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);
240
241 for (d = file->deps; d != 0; d = d->next)
242 {
243 if (d->need_2nd_expansion || d->ignore_automatic_vars)
244 continue;
245
246 slot = hash_find_slot (&dep_hash, d);
247 if (HASH_VACANT (*slot))
248 hash_insert_at (&dep_hash, d, slot);
249 else
250 {
251 /* Check if the two prerequisites have different ignore_mtime.
252 If so then we need to "upgrade" one that is order-only. */
253
254 struct dep* hd = (struct dep*) *slot;
255
256 if (d->ignore_mtime != hd->ignore_mtime)
257 d->ignore_mtime = hd->ignore_mtime = 0;
258 }
259 }
260
261 for (d = file->deps; d != 0; d = d->next)
262 {
263 const char *c;
264
265 if (d->need_2nd_expansion || d->ignore_automatic_vars || hash_find_item (&dep_hash, d) != d)
266 continue;
267
268 c = dep_name (d);
269 #ifndef NO_ARCHIVES
270 if (ar_name (c))
271 {
272 c = strchr (c, '(') + 1;
273 len = strlen (c) - 1;
274 }
275 else
276 #endif
277 len = strlen (c);
278
279 if (d->ignore_mtime)
280 {
281 memcpy (bp, c, len);
282 bp += len;
283 *bp++ = FILE_LIST_SEPARATOR;
284 }
285 else
286 {
287 memcpy (cp, c, len);
288 cp += len;
289 *cp++ = FILE_LIST_SEPARATOR;
290 if (d->changed || always_make_flag)
291 {
292 memcpy (qp, c, len);
293 qp += len;
294 *qp++ = FILE_LIST_SEPARATOR;
295 }
296 }
297 }
298
299 hash_free (&dep_hash, 0);
300
301 /* Kill the last spaces and define the variables. */
302
303 cp[cp > caret_value ? -1 : 0] = '\0';
304 DEFINE_VARIABLE ("^", 1, caret_value);
305
306 qp[qp > qmark_value ? -1 : 0] = '\0';
307 DEFINE_VARIABLE ("?", 1, qmark_value);
308
309 bp[bp > bar_value ? -1 : 0] = '\0';
310 DEFINE_VARIABLE ("|", 1, bar_value);
311 }
312
313 #undef DEFINE_VARIABLE
314 }
315
316 /* Chop CMDS up into individual command lines if necessary.
317 Also set the 'lines_flags' and 'any_recurse' members. */
318
319 void
320 chop_commands (struct commands *cmds)
321 {
322 unsigned int nlines;
323 unsigned short idx;
324 char **lines;
325
326 /* If we don't have any commands,
327 or we already parsed them, never mind. */
328
329 if (!cmds || cmds->command_lines != 0)
330 return;
331
332 /* Chop CMDS->commands up into lines in CMDS->command_lines. */
333
334 if (one_shell)
335 {
336 size_t l = strlen (cmds->commands);
337
338 nlines = 1;
339 lines = xmalloc (nlines * sizeof (char *));
340 lines[0] = xstrdup (cmds->commands);
341
342 /* Strip the trailing newline. */
343 if (l > 0 && lines[0][l-1] == '\n')
344 lines[0][l-1] = '\0';
345 }
346 else
347 {
348 const char *p;
349
350 nlines = 5;
351 lines = xmalloc (nlines * sizeof (char *));
352 idx = 0;
353 p = cmds->commands;
354 while (*p != '\0')
355 {
356 const char *end = p;
357 find_end:;
358 end = strchr (end, '\n');
359 if (end == 0)
360 end = p + strlen (p);
361 else if (end > p && end[-1] == '\\')
362 {
363 int backslash = 1;
364 const char *b;
365 for (b = end - 2; b >= p && *b == '\\'; --b)
366 backslash = !backslash;
367 if (backslash)
368 {
369 ++end;
370 goto find_end;
371 }
372 }
373
374 if (idx == nlines)
375 {
376 nlines += 2;
377 lines = xrealloc (lines, nlines * sizeof (char *));
378 }
379 lines[idx++] = xstrndup (p, (size_t) (end - p));
380 p = end;
381 if (*p != '\0')
382 ++p;
383 }
384
385 if (idx != nlines)
386 {
387 nlines = idx;
388 lines = xrealloc (lines, nlines * sizeof (char *));
389 }
390 }
391
392 /* Finally, set the corresponding CMDS->lines_flags elements and the
393 CMDS->any_recurse flag. */
394
395 if (nlines > USHRT_MAX)
396 ON (fatal, &cmds->fileinfo, _("Recipe has too many lines (%ud)"), nlines);
397
398 cmds->ncommand_lines = (unsigned short)nlines;
399 cmds->command_lines = lines;
400
401 cmds->any_recurse = 0;
402 cmds->lines_flags = xmalloc (nlines);
403
404 for (idx = 0; idx < nlines; ++idx)
405 {
406 unsigned char flags = 0;
407 const char *p = lines[idx];
408
409 while (ISBLANK (*p) || *p == '-' || *p == '@' || *p == '+')
410 switch (*(p++))
411 {
412 case '+':
413 flags |= COMMANDS_RECURSE;
414 break;
415 case '@':
416 flags |= COMMANDS_SILENT;
417 break;
418 case '-':
419 flags |= COMMANDS_NOERROR;
420 break;
421 }
422
423 /* If no explicit '+' was given, look for MAKE variable references. */
424 if (!(flags & COMMANDS_RECURSE)
425 && (strstr (p, "$(MAKE)") != 0 || strstr (p, "${MAKE}") != 0))
426 flags |= COMMANDS_RECURSE;
427
428 cmds->lines_flags[idx] = flags;
429 cmds->any_recurse |= flags & COMMANDS_RECURSE ? 1 : 0;
430 }
431 }
432
433 /* Expand the command lines and store the results in LINES. */
434 void expand_command_lines(struct commands *cmds, /*out*/ char **lines,
435 struct file *file)
436 {
437 unsigned int i;
438
439 for (i = 0; i < cmds->ncommand_lines; ++i)
440 {
441 /* Collapse backslash-newline combinations that are inside variable
442 or function references. These are left alone by the parser so
443 that they will appear in the echoing of commands (where they look
444 nice); and collapsed by construct_command_argv when it tokenizes.
445 But letting them survive inside function invocations loses because
446 we don't want the functions to see them as part of the text. */
447
448 char *in, *out, *ref;
449
450 /* IN points to where in the line we are scanning.
451 OUT points to where in the line we are writing.
452 When we collapse a backslash-newline combination,
453 IN gets ahead of OUT. */
454
455 in = out = cmds->command_lines[i];
456 while ((ref = strchr (in, '$')) != 0)
457 {
458 ++ref; /* Move past the $. */
459
460 if (out != in)
461 /* Copy the text between the end of the last chunk
462 we processed (where IN points) and the new chunk
463 we are about to process (where REF points). */
464 memmove (out, in, ref - in);
465
466 /* Move both pointers past the boring stuff. */
467 out += ref - in;
468 in = ref;
469
470 if (*ref == '(' || *ref == '{')
471 {
472 char openparen = *ref;
473 char closeparen = openparen == '(' ? ')' : '}';
474 int count;
475 char *p;
476
477 *out++ = *in++; /* Copy OPENPAREN. */
478 /* IN now points past the opening paren or brace.
479 Count parens or braces until it is matched. */
480 count = 0;
481 while (*in != '\0')
482 {
483 if (*in == closeparen && --count < 0)
484 break;
485 else if (*in == '\\' && in[1] == '\n')
486 {
487 /* We have found a backslash-newline inside a
488 variable or function reference. Eat it and
489 any following whitespace. */
490
491 int quoted = 0;
492 for (p = in - 1; p > ref && *p == '\\'; --p)
493 quoted = !quoted;
494
495 if (quoted)
496 /* There were two or more backslashes, so this is
497 not really a continuation line. We don't collapse
498 the quoting backslashes here as is done in
499 collapse_continuations, because the line will
500 be collapsed again after expansion. */
501 *out++ = *in++;
502 else
503 {
504 /* Skip the backslash, newline and
505 any following whitespace. */
506 in = next_token (in + 2);
507
508 /* Discard any preceding whitespace that has
509 already been written to the output. */
510 while (out > ref
511 && isblank ((unsigned char)out[-1]))
512 --out;
513
514 /* Replace it all with a single space. */
515 *out++ = ' ';
516 }
517 }
518 else
519 {
520 if (*in == openparen)
521 ++count;
522
523 *out++ = *in++;
524 }
525 }
526 }
527 }
528
529 /* There are no more references in this line to worry about.
530 Copy the remaining uninteresting text to the output. */
531 if (out != in)
532 memmove (out, in, strlen (in) + 1);
533
534 /* Finally, expand the line. */
535 lines[i] = allocated_variable_expand_for_file (cmds->command_lines[i],
536 file);
537 }
538
539 }
540
541 /* Execute the commands to remake FILE. If they are currently executing,
542 return or have already finished executing, just return. Otherwise,
543 fork off a child process to run the first command line in the sequence. */
544
545 void
546 execute_file_commands (file_t *file, target_stack_node_t *p_call_stack)
547 {
548 const char *p;
549
550 /* Don't go through all the preparations if
551 the commands are nothing but whitespace. */
552
553 for (p = file->cmds->commands; *p != '\0'; ++p)
554 if (!ISSPACE (*p) && *p != '-' && *p != '@' && *p != '+')
555 break;
556 if (*p == '\0')
557 {
558 /* If there are no commands, assume everything worked. */
559 set_command_state (file, cs_running);
560 file->update_status = us_success;
561 notice_finished_file (file);
562 return;
563 }
564
565 /* First set the automatic variables according to this file. */
566
567 initialize_file_variables (file, 0);
568
569 set_file_variables (file);
570
571 /* If this is a loaded dynamic object, unload it before remaking.
572 Some systems don't support overwriting a loaded object. */
573 if (file->loaded)
574 unload_file (file->name);
575
576 /* Start the commands running. */
577 new_job (file, p_call_stack);
578 }
579
580 /* This is set while we are inside fatal_error_signal,
581 so things can avoid nonreentrant operations. */
582
583 int handling_fatal_signal = 0;
584
585 /* Handle fatal signals. */
586
587 RETSIGTYPE
588 fatal_error_signal (int sig)
589 {
590 #ifdef __MSDOS__
591 extern int dos_status, dos_command_running;
592
593 if (dos_command_running)
594 {
595 /* That was the child who got the signal, not us. */
596 dos_status |= (sig << 8);
597 return;
598 }
599 remove_intermediates (1);
600 exit (EXIT_FAILURE);
601 #else /* not __MSDOS__ */
602 #ifdef WINDOWS32
603 extern HANDLE main_thread;
604
605 /* Windows creates a sperate thread for handling Ctrl+C, so we need
606 to suspend the main thread, or else we will have race conditions
607 when both threads call reap_children. */
608 if (main_thread)
609 {
610 DWORD susp_count = SuspendThread (main_thread);
611
612 if (susp_count != 0)
613 fprintf (stderr, "SuspendThread: suspend count = %ld\n", susp_count);
614 else if (susp_count == (DWORD)-1)
615 {
616 DWORD ierr = GetLastError ();
617
618 fprintf (stderr, "SuspendThread: error %ld: %s\n",
619 ierr, map_windows32_error_to_string (ierr));
620 }
621 }
622 #endif
623 handling_fatal_signal = 1;
624
625 /* Set the handling for this signal to the default.
626 It is blocked now while we run this handler. */
627 signal (sig, SIG_DFL);
628
629 /* A termination signal won't be sent to the entire
630 process group, but it means we want to kill the children. */
631
632 if (sig == SIGTERM)
633 {
634 struct child *c;
635 for (c = children; c != 0; c = c->next)
636 if (!c->remote && c->pid > 0)
637 (void) kill (c->pid, SIGTERM);
638 }
639
640 /* If we got a signal that means the user
641 wanted to kill make, remove pending targets. */
642
643 if (sig == SIGTERM || sig == SIGINT
644 #ifdef SIGHUP
645 || sig == SIGHUP
646 #endif
647 #ifdef SIGQUIT
648 || sig == SIGQUIT
649 #endif
650 )
651 {
652 struct child *c;
653
654 /* Remote children won't automatically get signals sent
655 to the process group, so we must send them. */
656 for (c = children; c != 0; c = c->next)
657 if (c->remote && c->pid > 0)
658 (void) remote_kill (c->pid, sig);
659
660 for (c = children; c != 0; c = c->next)
661 delete_child_targets (c);
662
663 /* Clean up the children. We don't just use the call below because
664 we don't want to print the "Waiting for children" message. */
665 while (job_slots_used > 0)
666 reap_children (1, 0, NULL);
667 }
668 else
669 /* Wait for our children to die. */
670 while (job_slots_used > 0)
671 reap_children (1, 1, NULL);
672
673 /* Delete any non-precious intermediate files that were made. */
674
675 remove_intermediates (1);
676
677 #ifdef SIGQUIT
678 if (sig == SIGQUIT)
679 /* We don't want to send ourselves SIGQUIT, because it will
680 cause a core dump. Just exit instead. */
681 exit (MAKE_TROUBLE);
682 #endif
683
684 #ifdef WINDOWS32
685 if (main_thread)
686 CloseHandle (main_thread);
687 /* Cannot call W32_kill with a pid (it needs a handle). The exit
688 status of 130 emulates what happens in Bash. */
689 exit (130);
690 #else
691 /* Signal the same code; this time it will really be fatal. The signal
692 will be unblocked when we return and arrive then to kill us. */
693 if (kill (getpid (), sig) < 0)
694 pfatal_with_name ("kill");
695 #endif /* not WINDOWS32 */
696 #endif /* not __MSDOS__ */
697 }
698
699 /* Delete FILE unless it's precious or not actually a file (phony),
700 and it has changed on disk since we last stat'd it. */
701
702 static void
703 delete_target (struct file *file, const char *on_behalf_of)
704 {
705 struct stat st;
706 int e;
707
708 if (file->precious || file->phony)
709 return;
710
711 #ifndef NO_ARCHIVES
712 if (ar_name (file->name))
713 {
714 time_t file_date = (file->last_mtime == NONEXISTENT_MTIME
715 ? (time_t) -1
716 : (time_t) FILE_TIMESTAMP_S (file->last_mtime));
717 time_t member_date = NONEXISTENT_MTIME;
718 int found;
719 found = ar_member_date (file->name, &member_date);
720 if (found && member_date != file_date)
721 {
722 if (on_behalf_of)
723 OSS (error, NILF,
724 _("*** [%s] Archive member '%s' may be bogus; not deleted"),
725 on_behalf_of, file->name);
726 else
727 OS (error, NILF,
728 _("*** Archive member '%s' may be bogus; not deleted"),
729 file->name);
730 }
731 return;
732 }
733 #endif
734
735 EINTRLOOP (e, stat (file->name, &st));
736 if (e == 0
737 && S_ISREG (st.st_mode)
738 && FILE_TIMESTAMP_STAT_MODTIME (file->name, st) != file->last_mtime)
739 {
740 if (on_behalf_of)
741 OSS (error, NILF,
742 _("*** [%s] Deleting file '%s'"), on_behalf_of, file->name);
743 else
744 OS (error, NILF, _("*** Deleting file '%s'"), file->name);
745 if (unlink (file->name) < 0
746 && errno != ENOENT) /* It disappeared; so what. */
747 perror_with_name ("unlink: ", file->name);
748 }
749 }
750
751
752 /* Delete all non-precious targets of CHILD unless they were already deleted.
753 Set the flag in CHILD to say they've been deleted. */
754
755 void
756 delete_child_targets (struct child *child)
757 {
758 struct dep *d;
759
760 if (child->deleted || child->pid < 0)
761 return;
762
763 /* Delete the target file if it changed. */
764 delete_target (child->file, NULL);
765
766 /* Also remove any non-precious targets listed in the 'also_make' member. */
767 for (d = child->file->also_make; d != 0; d = d->next)
768 delete_target (d->file, child->file->name);
769
770 child->deleted = 1;
771 }
772
773 /*!
774 Print out the commands.
775
776 @param p_cmds location of commands to print out.
777 @param p_target used to set automatic variables if it is non-null.
778 @param b_expand if true, expand the commands to remove MAKE variables.
779 */
780 void
781 print_commands (file_t *p_target, commands_t *p_cmds, bool b_expand)
782 {
783 const char *s;
784
785 fputs (_("# recipe to execute"), stdout);
786
787 if (p_cmds->fileinfo.filenm == 0)
788 puts (_(" (built-in):"));
789 else
790 printf (_(" (from '%s', line %lu):\n"),
791 p_cmds->fileinfo.filenm, p_cmds->fileinfo.lineno);
792
793 if (b_expand && p_target) {
794 variable_set_list_t *p_file_vars = NULL;
795 initialize_file_variables (p_target, 0);
796 set_file_variables (p_target);
797 p_file_vars = p_target->variables;
798 s = variable_expand_set(p_cmds->commands, p_file_vars);
799 } else {
800 s = p_cmds->commands;
801 }
802
803 while (*s != '\0')
804 {
805 const char *end;
806 int bs;
807
808 /* Print one full logical recipe line: find a non-escaped newline. */
809 for (end = s, bs = 0; *end != '\0'; ++end)
810 {
811 if (*end == '\n' && !bs)
812 break;
813
814 bs = *end == '\\' ? !bs : 0;
815 }
816
817 printf ("%c%.*s\n", cmd_prefix, (int) (end - s), s);
818
819 s = end + (end[0] == '\n');
820 }
821 }