2 * $OpenBSD: patch.c,v 1.43 2004/11/19 20:08:11 otto Exp $
3 * $DragonFly: src/usr.bin/patch/patch.c,v 1.4 2005/01/10 21:45:33 swildner Exp $
7 * patch - a program to apply diffs to original files
9 * Copyright 1986, Larry Wall
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following condition is met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this condition and the following disclaimer.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * -C option added in 1998, original code by Marc Espie, based on FreeBSD
32 #include <sys/types.h>
47 #include "backupfile.h"
48 #include "pathnames.h"
52 char buf[MAXLINELEN]; /* general purpose buffer */
54 bool using_plan_a = true; /* try to keep everything in memory */
55 bool out_of_mem = false; /* ran out of memory in plan a */
59 char *filearg[MAXFILEC];
60 bool ok_to_create_file = false;
62 char *origprae = NULL;
67 bool toutkeep = false;
68 bool trejkeep = false;
69 bool warn_on_invalid_line;
70 bool last_line_missing_eol;
80 bool noreverse = false;
81 bool skip_rest_of_patch = false;
83 bool canonicalize = false;
84 bool check_only = false;
86 char *revision = NULL; /* prerequisite revision, if any */
87 LINENUM input_lines = 0; /* how long is input file in lines */
88 int posix = 0; /* strict POSIX mode? */
90 static void reinitialize_almost_everything(void);
91 static void get_some_switches(void);
92 static LINENUM locate_hunk(LINENUM);
93 static void abort_context_hunk(void);
94 static void rej_line(int, LINENUM);
95 static void abort_hunk(void);
96 static void apply_hunk(LINENUM);
97 static void init_output(const char *);
98 static void init_reject(const char *);
99 static void copy_till(LINENUM, bool);
100 static void spew_output(void);
101 static void dump_line(LINENUM, bool);
102 static bool patch_match(LINENUM, LINENUM, LINENUM);
103 static bool similar(const char *, const char *, int);
104 static void usage(void);
106 /* true if -E was specified on command line. */
107 static bool remove_empty_files = false;
109 /* true if -R was specified on command line. */
110 static bool reverse_flag_specified = false;
112 /* buffer holding the name of the rejected patch file. */
113 static char rejname[NAME_MAX + 1];
115 /* buffer for stderr */
116 static char serrbuf[BUFSIZ];
118 /* how many input lines have been irretractibly output */
119 static LINENUM last_frozen_line = 0;
121 static int Argc; /* guess */
123 static int Argc_last; /* for restarting plan_b */
124 static char **Argv_last;
126 static FILE *ofp = NULL; /* output file pointer */
127 static FILE *rejfp = NULL; /* reject file pointer */
129 static int filec = 0; /* how many file arguments? */
130 static LINENUM last_offset = 0;
131 static LINENUM maxfuzz = 2;
133 /* patch using ifdef, ifndef, etc. */
134 static bool do_defines = false;
136 static char if_defined[128];
138 static char not_defined[128];
140 static const char else_defined[] = "#else\n";
142 static char end_defined[128];
145 /* Apply a set of diffs as appropriate. */
148 main(int argc, char *argv[])
150 int error = 0, hunk, failed, i, fd;
151 LINENUM where = 0, newwhere, fuzz, mymaxfuzz;
155 setbuf(stderr, serrbuf);
156 for (i = 0; i < MAXFILEC; i++)
159 /* Cons up the names of the temporary files. */
160 if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
162 for (i = strlen(tmpdir) - 1; i > 0 && tmpdir[i] == '/'; i--)
165 if (asprintf(&TMPOUTNAME, "%.*s/patchoXXXXXXXXXX", i, tmpdir) == -1)
166 fatal("cannot allocate memory");
167 if ((fd = mkstemp(TMPOUTNAME)) < 0)
168 pfatal("can't create %s", TMPOUTNAME);
171 if (asprintf(&TMPINNAME, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
172 fatal("cannot allocate memory");
173 if ((fd = mkstemp(TMPINNAME)) < 0)
174 pfatal("can't create %s", TMPINNAME);
177 if (asprintf(&TMPREJNAME, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
178 fatal("cannot allocate memory");
179 if ((fd = mkstemp(TMPREJNAME)) < 0)
180 pfatal("can't create %s", TMPREJNAME);
183 if (asprintf(&TMPPATNAME, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
184 fatal("cannot allocate memory");
185 if ((fd = mkstemp(TMPPATNAME)) < 0)
186 pfatal("can't create %s", TMPPATNAME);
189 v = getenv("SIMPLE_BACKUP_SUFFIX");
191 simple_backup_suffix = v;
193 simple_backup_suffix = ORIGEXT;
200 if (backup_type == none) {
201 if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL)
202 v = getenv("VERSION_CONTROL");
203 if (v != NULL || !posix)
204 backup_type = get_version(v); /* OK to pass NULL. */
207 /* make sure we clean up /tmp in case of disaster */
210 for (open_patch_file(filearg[1]); there_is_another_patch();
211 reinitialize_almost_everything()) {
212 /* for each patch in patch file */
214 warn_on_invalid_line = true;
217 outname = savestr(filearg[0]);
219 /* for ed script just up and do it and exit */
220 if (diff_type == ED_DIFF) {
224 /* initialize the patched file */
225 if (!skip_rest_of_patch)
226 init_output(TMPOUTNAME);
228 /* initialize reject file */
229 init_reject(TMPREJNAME);
231 /* find out where all the lines are */
232 if (!skip_rest_of_patch)
233 scan_input(filearg[0]);
235 /* from here on, open no standard i/o files, because malloc */
236 /* might misfire and we can't catch it easily */
238 /* apply each hunk of patch */
242 while (another_hunk()) {
245 mymaxfuzz = pch_context();
246 if (maxfuzz < mymaxfuzz)
248 if (!skip_rest_of_patch) {
250 where = locate_hunk(fuzz);
251 if (hunk == 1 && where == 0 && !force) {
252 /* dwim for reversed patch? */
255 say("Not enough memory to try swapped hunk! Assuming unswapped.\n");
260 where = locate_hunk(fuzz);
262 /* didn't find it swapped */
264 /* put it back to normal */
265 fatal("lost hunk on alloc error!\n");
267 } else if (noreverse) {
269 /* put it back to normal */
270 fatal("lost hunk on alloc error!\n");
272 say("Ignoring previously applied (or reversed) patch.\n");
273 skip_rest_of_patch = true;
276 say("%seversed (or previously applied) patch detected! %s -R.",
277 reverse ? "R" : "Unr",
278 reverse ? "Assuming" : "Ignoring");
280 ask("%seversed (or previously applied) patch detected! %s -R? [y] ",
281 reverse ? "R" : "Unr",
282 reverse ? "Assume" : "Ignore");
284 ask("Apply anyway? [n] ");
286 skip_rest_of_patch = true;
290 /* put it back to normal */
291 fatal("lost hunk on alloc error!\n");
295 } while (!skip_rest_of_patch && where == 0 &&
296 ++fuzz <= mymaxfuzz);
298 if (skip_rest_of_patch) { /* just got decided */
303 newwhere = pch_newfirst() + last_offset;
304 if (skip_rest_of_patch) {
308 say("Hunk #%d ignored at %ld.\n",
310 } else if (where == 0) {
314 say("Hunk #%d failed at %ld.\n",
319 say("Hunk #%d succeeded at %ld",
322 say(" with fuzz %ld", fuzz);
324 say(" (offset %ld line%s)",
326 last_offset == 1L ? "" : "s");
332 if (out_of_mem && using_plan_a) {
335 say("\n\nRan out of memory using Plan A--trying again...\n\n");
345 fatal("Internal error: hunk should not be 0\n");
347 /* finish spewing out the new file */
348 if (!skip_rest_of_patch)
351 /* and put the output where desired */
353 if (!skip_rest_of_patch) {
355 char *realout = outname;
358 if (move_file(TMPOUTNAME, outname) < 0) {
360 realout = TMPOUTNAME;
361 chmod(TMPOUTNAME, filemode);
363 chmod(outname, filemode);
365 if (remove_empty_files &&
366 stat(realout, &statbuf) == 0 &&
367 statbuf.st_size == 0) {
369 say("Removing %s (empty after patching).\n",
379 if (*rejname == '\0') {
380 if (strlcpy(rejname, outname,
381 sizeof(rejname)) >= sizeof(rejname))
382 fatal("filename %s is too long\n", outname);
383 if (strlcat(rejname, REJEXT,
384 sizeof(rejname)) >= sizeof(rejname))
385 fatal("filename %s is too long\n", outname);
387 if (skip_rest_of_patch) {
388 say("%d out of %d hunks ignored--saving rejects to %s\n",
389 failed, hunk, rejname);
391 say("%d out of %d hunks failed--saving rejects to %s\n",
392 failed, hunk, rejname);
394 if (!check_only && move_file(TMPREJNAME, rejname) < 0)
403 /* Prepare to find the next patch to do in the patch file. */
406 reinitialize_almost_everything(void)
412 last_frozen_line = 0;
429 reverse = reverse_flag_specified;
430 skip_rest_of_patch = false;
435 /* Process switches and filenames. */
438 get_some_switches(void)
440 const char *options = "b::B:cCd:D:eEfF:i:lnNo:p:r:RstuvV:x:z:";
441 static struct option longopts[] = {
442 {"backup", no_argument, 0, 'b'},
443 {"batch", no_argument, 0, 't'},
444 {"check", no_argument, 0, 'C'},
445 {"context", no_argument, 0, 'c'},
446 {"debug", required_argument, 0, 'x'},
447 {"directory", required_argument, 0, 'd'},
448 {"ed", no_argument, 0, 'e'},
449 {"force", no_argument, 0, 'f'},
450 {"forward", no_argument, 0, 'N'},
451 {"fuzz", required_argument, 0, 'F'},
452 {"ifdef", required_argument, 0, 'D'},
453 {"input", required_argument, 0, 'i'},
454 {"ignore-whitespace", no_argument, 0, 'l'},
455 {"normal", no_argument, 0, 'n'},
456 {"output", required_argument, 0, 'o'},
457 {"prefix", required_argument, 0, 'B'},
458 {"quiet", no_argument, 0, 's'},
459 {"reject-file", required_argument, 0, 'r'},
460 {"remove-empty-files", no_argument, 0, 'E'},
461 {"reverse", no_argument, 0, 'R'},
462 {"silent", no_argument, 0, 's'},
463 {"strip", required_argument, 0, 'p'},
464 {"suffix", required_argument, 0, 'z'},
465 {"unified", no_argument, 0, 'u'},
466 {"version", no_argument, 0, 'v'},
467 {"version-control", required_argument, 0, 'V'},
468 {"posix", no_argument, &posix, 1},
478 optreset = optind = 1;
479 while ((ch = getopt_long(Argc, Argv, options, longopts, NULL)) != -1) {
482 if (backup_type == none)
483 backup_type = numbered_existing;
487 say("Warning, the ``-b suffix'' option has been"
488 " obsoleted by the -z option.\n");
491 /* must directly follow 'b' case for backwards compat */
492 simple_backup_suffix = savestr(optarg);
495 origprae = savestr(optarg);
498 diff_type = CONTEXT_DIFF;
504 if (chdir(optarg) < 0)
505 pfatal("can't cd to %s", optarg);
509 if (!isalpha(*optarg) && *optarg != '_')
510 fatal("argument to -D is not an identifier\n");
511 snprintf(if_defined, sizeof if_defined,
512 "#ifdef %s\n", optarg);
513 snprintf(not_defined, sizeof not_defined,
514 "#ifndef %s\n", optarg);
515 snprintf(end_defined, sizeof end_defined,
516 "#endif /* %s */\n", optarg);
522 remove_empty_files = true;
528 maxfuzz = atoi(optarg);
531 if (++filec == MAXFILEC)
532 fatal("too many file arguments\n");
533 filearg[filec] = savestr(optarg);
539 diff_type = NORMAL_DIFF;
545 outname = savestr(optarg);
548 strippath = atoi(optarg);
551 if (strlcpy(rejname, optarg,
552 sizeof(rejname)) >= sizeof(rejname))
553 fatal("argument for -r is too long\n");
557 reverse_flag_specified = true;
566 diff_type = UNI_DIFF;
572 backup_type = get_version(optarg);
576 debug = atoi(optarg);
589 filearg[0] = savestr(*Argv++);
592 if (++filec == MAXFILEC)
593 fatal("too many file arguments\n");
594 filearg[filec] = savestr(*Argv++);
599 if (getenv("POSIXLY_CORRECT") != NULL)
607 "usage: patch [-bcCeEflnNRstuv] [-B backup-prefix] [-d directory] [-D symbol]\n"
608 " [-F max-fuzz] [-i patchfile] [-o out-file] [-p strip-count]\n"
609 " [-r rej-name] [-V {numbered,existing,simple}] [-z backup-ext]\n"
610 " [origfile [patchfile]]\n");
611 my_exit(EXIT_SUCCESS);
615 * Attempt to find the right place to apply this hunk of patch.
618 locate_hunk(LINENUM fuzz)
620 LINENUM first_guess = pch_first() + last_offset;
622 LINENUM pat_lines = pch_ptrn_lines();
623 LINENUM max_pos_offset = input_lines - first_guess - pat_lines + 1;
624 LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + pch_context();
626 if (pat_lines == 0) { /* null range matches always */
627 if (verbose && fuzz == 0 && (diff_type == CONTEXT_DIFF
628 || diff_type == NEW_CONTEXT_DIFF
629 || diff_type == UNI_DIFF)) {
630 say("Empty context always matches.\n");
632 if (diff_type == CONTEXT_DIFF
633 || diff_type == NEW_CONTEXT_DIFF
634 || diff_type == UNI_DIFF) {
636 return (input_lines == 0 ? first_guess : 0);
638 return (first_guess);
640 if (max_neg_offset >= first_guess) /* do not try lines < 0 */
641 max_neg_offset = first_guess - 1;
642 if (first_guess <= input_lines && patch_match(first_guess, 0, fuzz))
644 for (offset = 1; ; offset++) {
645 bool check_after = (offset <= max_pos_offset);
646 bool check_before = (offset <= max_neg_offset);
648 if (check_after && patch_match(first_guess, offset, fuzz)) {
651 say("Offset changing from %ld to %ld\n",
652 last_offset, offset);
654 last_offset = offset;
655 return first_guess + offset;
656 } else if (check_before && patch_match(first_guess, -offset, fuzz)) {
659 say("Offset changing from %ld to %ld\n",
660 last_offset, -offset);
662 last_offset = -offset;
663 return first_guess - offset;
664 } else if (!check_before && !check_after)
669 /* We did not find the pattern, dump out the hunk so they can handle it. */
672 abort_context_hunk(void)
675 const LINENUM pat_end = pch_end();
677 * add in last_offset to guess the same as the previous successful
680 const LINENUM oldfirst = pch_first() + last_offset;
681 const LINENUM newfirst = pch_newfirst() + last_offset;
682 const LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1;
683 const LINENUM newlast = newfirst + pch_repl_lines() - 1;
684 const char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : "");
685 const char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----");
687 fprintf(rejfp, "***************\n");
688 for (i = 0; i <= pat_end; i++) {
689 switch (pch_char(i)) {
691 if (oldlast < oldfirst)
692 fprintf(rejfp, "*** 0%s\n", stars);
693 else if (oldlast == oldfirst)
694 fprintf(rejfp, "*** %ld%s\n", oldfirst, stars);
696 fprintf(rejfp, "*** %ld,%ld%s\n", oldfirst,
700 if (newlast < newfirst)
701 fprintf(rejfp, "--- 0%s\n", minuses);
702 else if (newlast == newfirst)
703 fprintf(rejfp, "--- %ld%s\n", newfirst, minuses);
705 fprintf(rejfp, "--- %ld,%ld%s\n", newfirst,
709 fprintf(rejfp, "%s", pfetch(i));
715 fprintf(rejfp, "%c %s", pch_char(i), pfetch(i));
718 fatal("fatal internal error in abort_context_hunk\n");
724 rej_line(int ch, LINENUM i)
727 const char *line = pfetch(i);
731 fprintf(rejfp, "%c%s", ch, line);
732 if (len == 0 || line[len-1] != '\n')
733 fprintf(rejfp, "\n\\ No newline at end of file\n");
741 const LINENUM pat_end = pch_end();
742 const LINENUM oldfirst = pch_first() + last_offset;
743 const LINENUM newfirst = pch_newfirst() + last_offset;
745 if (diff_type != UNI_DIFF) {
746 abort_context_hunk();
750 for (i = 0; i <= pat_end; i++) {
751 if (pch_char(i) == '=') {
757 fprintf(rejfp, "malformed hunk: no split found\n");
762 fprintf(rejfp, "@@ -%ld,%ld +%ld,%ld @@\n",
763 pch_ptrn_lines() ? oldfirst : 0,
764 pch_ptrn_lines(), newfirst, pch_repl_lines());
765 while (i < split || j <= pat_end) {
766 ch1 = i < split ? pch_char(i) : -1;
767 ch2 = j <= pat_end ? pch_char(j) : -1;
771 } else if (ch1 == ' ' && ch2 == ' ') {
775 } else if (ch1 == '!' && ch2 == '!') {
776 while (i < split && ch1 == '!') {
779 ch1 = i < split ? pch_char(i) : -1;
781 while (j <= pat_end && ch2 == '!') {
784 ch2 = j <= pat_end ? pch_char(j) : -1;
786 } else if (ch1 == '*') {
788 } else if (ch2 == '+' || ch2 == ' ') {
792 fprintf(rejfp, "internal error on (%ld %ld %ld)\n",
801 /* We found where to apply it (we hope), so do it. */
804 apply_hunk(LINENUM where)
807 const LINENUM lastline = pch_ptrn_lines();
808 LINENUM new = lastline + 1;
813 int def_state = OUTSIDE;
814 const LINENUM pat_end = pch_end();
817 while (pch_char(new) == '=' || pch_char(new) == '\n')
820 while (old <= lastline) {
821 if (pch_char(old) == '-') {
822 copy_till(where + old - 1, false);
824 if (def_state == OUTSIDE) {
825 fputs(not_defined, ofp);
826 def_state = IN_IFNDEF;
827 } else if (def_state == IN_IFDEF) {
828 fputs(else_defined, ofp);
831 fputs(pfetch(old), ofp);
835 } else if (new > pat_end) {
837 } else if (pch_char(new) == '+') {
838 copy_till(where + old - 1, false);
840 if (def_state == IN_IFNDEF) {
841 fputs(else_defined, ofp);
843 } else if (def_state == OUTSIDE) {
844 fputs(if_defined, ofp);
845 def_state = IN_IFDEF;
848 fputs(pfetch(new), ofp);
850 } else if (pch_char(new) != pch_char(old)) {
851 say("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
852 pch_hunk_beg() + old,
853 pch_hunk_beg() + new);
855 say("oldchar = '%c', newchar = '%c'\n",
856 pch_char(old), pch_char(new));
859 } else if (pch_char(new) == '!') {
860 copy_till(where + old - 1, false);
862 fputs(not_defined, ofp);
863 def_state = IN_IFNDEF;
865 while (pch_char(old) == '!') {
867 fputs(pfetch(old), ofp);
873 fputs(else_defined, ofp);
876 while (pch_char(new) == '!') {
877 fputs(pfetch(new), ofp);
881 if (pch_char(new) != ' ')
882 fatal("Internal error: expected ' '\n");
885 if (do_defines && def_state != OUTSIDE) {
886 fputs(end_defined, ofp);
891 if (new <= pat_end && pch_char(new) == '+') {
892 copy_till(where + old - 1, false);
894 if (def_state == OUTSIDE) {
895 fputs(if_defined, ofp);
896 def_state = IN_IFDEF;
897 } else if (def_state == IN_IFNDEF) {
898 fputs(else_defined, ofp);
902 while (new <= pat_end && pch_char(new) == '+') {
903 fputs(pfetch(new), ofp);
907 if (do_defines && def_state != OUTSIDE) {
908 fputs(end_defined, ofp);
916 init_output(const char *name)
918 ofp = fopen(name, "w");
920 pfatal("can't create %s", name);
924 * Open a file to put hunks we can't locate.
927 init_reject(const char *name)
929 rejfp = fopen(name, "w");
931 pfatal("can't create %s", name);
935 * Copy input file to output, up to wherever hunk is to be applied.
936 * If endoffile is true, treat the last line specially since it may
940 copy_till(LINENUM lastline, bool endoffile)
942 if (last_frozen_line > lastline)
943 fatal("misordered hunks! output would be garbled\n");
944 while (last_frozen_line < lastline) {
945 if (++last_frozen_line == lastline && endoffile)
946 dump_line(last_frozen_line, !last_line_missing_eol);
948 dump_line(last_frozen_line, true);
953 * Finish copying the input file to the output file.
960 say("il=%ld lfl=%ld\n", input_lines, last_frozen_line);
963 copy_till(input_lines, true); /* dump remainder of file */
969 * Copy one line from input to output.
972 dump_line(LINENUM line, bool write_newline)
979 /* Note: string is not NUL terminated. */
980 for (; *s != '\n'; s++)
987 * Does the patch pattern match at line base+offset?
990 patch_match(LINENUM base, LINENUM offset, LINENUM fuzz)
992 LINENUM pline = 1 + fuzz;
994 LINENUM pat_lines = pch_ptrn_lines() - fuzz;
995 const char *ilineptr;
996 const char *plineptr;
999 for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) {
1000 ilineptr = ifetch(iline, offset >= 0);
1001 if (ilineptr == NULL)
1003 plineptr = pfetch(pline);
1004 plinelen = pch_line_len(pline);
1006 if (!similar(ilineptr, plineptr, plinelen))
1008 } else if (strnNE(ilineptr, plineptr, plinelen))
1010 if (iline == input_lines) {
1012 * We are looking at the last line of the file.
1013 * If the file has no eol, the patch line should
1014 * not have one either and vice-versa. Note that
1017 if (last_line_missing_eol) {
1018 if (plineptr[plinelen - 1] == '\n')
1021 if (plineptr[plinelen - 1] != '\n')
1030 * Do two lines match with canonicalized white space?
1033 similar(const char *a, const char *b, int len)
1036 if (isspace(*b)) { /* whitespace (or \n) to match? */
1037 if (!isspace(*a)) /* no corresponding whitespace? */
1039 while (len && isspace(*b) && *b != '\n')
1040 b++, len--; /* skip pattern whitespace */
1041 while (isspace(*a) && *a != '\n')
1042 a++; /* skip target whitespace */
1043 if (*a == '\n' || *b == '\n')
1044 return (*a == *b); /* should end in sync */
1045 } else if (*a++ != *b++) /* match non-whitespace chars */
1048 len--; /* probably not necessary */
1050 return true; /* actually, this is not reached */
1051 /* since there is always a \n */