2 * $OpenBSD: patch.c,v 1.45 2007/04/18 21:52:24 sobrado Exp $
3 * $DragonFly: src/usr.bin/patch/patch.c,v 1.8 2008/08/10 23:01:51 joerg 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"
50 mode_t filemode = 0644;
52 char buf[MAXLINELEN]; /* general purpose buffer */
53 size_t buf_len = sizeof(buf);
55 bool using_plan_a = true; /* try to keep everything in memory */
56 bool out_of_mem = false; /* ran out of memory in plan a */
60 char *filearg[MAXFILEC];
61 bool ok_to_create_file = false;
63 char *origprae = NULL;
68 bool toutkeep = false;
69 bool trejkeep = false;
70 bool warn_on_invalid_line;
71 bool last_line_missing_eol;
81 bool noreverse = false;
82 bool skip_rest_of_patch = false;
84 bool canonicalize = false;
85 bool check_only = false;
87 char *revision = NULL; /* prerequisite revision, if any */
88 LINENUM input_lines = 0; /* how long is input file in lines */
89 int posix = 0; /* strict POSIX mode? */
91 static void reinitialize_almost_everything(void);
92 static void get_some_switches(void);
93 static LINENUM locate_hunk(LINENUM);
94 static void abort_context_hunk(void);
95 static void rej_line(int, LINENUM);
96 static void abort_hunk(void);
97 static void apply_hunk(LINENUM);
98 static void init_output(const char *);
99 static void init_reject(const char *);
100 static void copy_till(LINENUM, bool);
101 static void spew_output(void);
102 static void dump_line(LINENUM, bool);
103 static bool patch_match(LINENUM, LINENUM, LINENUM);
104 static bool similar(const char *, const char *, int);
105 static void usage(void);
107 /* true if -E was specified on command line. */
108 static bool remove_empty_files = false;
110 /* true if -R was specified on command line. */
111 static bool reverse_flag_specified = false;
113 /* buffer holding the name of the rejected patch file. */
114 static char rejname[NAME_MAX + 1];
116 /* buffer for stderr */
117 static char serrbuf[BUFSIZ];
119 /* how many input lines have been irretractibly output */
120 static LINENUM last_frozen_line = 0;
122 static int Argc; /* guess */
124 static int Argc_last; /* for restarting plan_b */
125 static char **Argv_last;
127 static FILE *ofp = NULL; /* output file pointer */
128 static FILE *rejfp = NULL; /* reject file pointer */
130 static int filec = 0; /* how many file arguments? */
131 static LINENUM last_offset = 0;
132 static LINENUM maxfuzz = 2;
134 /* patch using ifdef, ifndef, etc. */
135 static bool do_defines = false;
137 static char if_defined[128];
139 static char not_defined[128];
141 static const char else_defined[] = "#else\n";
143 static char end_defined[128];
146 /* Apply a set of diffs as appropriate. */
149 main(int argc, char *argv[])
151 int error = 0, hunk, failed, i, fd;
152 LINENUM where = 0, newwhere, fuzz, mymaxfuzz;
156 setbuf(stderr, serrbuf);
157 for (i = 0; i < MAXFILEC; i++)
160 /* Cons up the names of the temporary files. */
161 if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
163 for (i = strlen(tmpdir) - 1; i > 0 && tmpdir[i] == '/'; i--)
166 if (asprintf(&TMPOUTNAME, "%.*s/patchoXXXXXXXXXX", i, tmpdir) == -1)
167 fatal("cannot allocate memory");
168 if ((fd = mkstemp(TMPOUTNAME)) < 0)
169 pfatal("can't create %s", TMPOUTNAME);
172 if (asprintf(&TMPINNAME, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
173 fatal("cannot allocate memory");
174 if ((fd = mkstemp(TMPINNAME)) < 0)
175 pfatal("can't create %s", TMPINNAME);
178 if (asprintf(&TMPREJNAME, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
179 fatal("cannot allocate memory");
180 if ((fd = mkstemp(TMPREJNAME)) < 0)
181 pfatal("can't create %s", TMPREJNAME);
184 if (asprintf(&TMPPATNAME, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
185 fatal("cannot allocate memory");
186 if ((fd = mkstemp(TMPPATNAME)) < 0)
187 pfatal("can't create %s", TMPPATNAME);
190 v = getenv("SIMPLE_BACKUP_SUFFIX");
192 simple_backup_suffix = v;
194 simple_backup_suffix = ORIGEXT;
201 if (backup_type == none) {
202 if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL)
203 v = getenv("VERSION_CONTROL");
204 if (v != NULL || !posix)
205 backup_type = get_version(v); /* OK to pass NULL. */
208 /* make sure we clean up /tmp in case of disaster */
211 for (open_patch_file(filearg[1]); there_is_another_patch();
212 reinitialize_almost_everything()) {
213 /* for each patch in patch file */
215 warn_on_invalid_line = true;
218 outname = savestr(filearg[0]);
220 /* for ed script just up and do it and exit */
221 if (diff_type == ED_DIFF) {
225 /* initialize the patched file */
226 if (!skip_rest_of_patch)
227 init_output(TMPOUTNAME);
229 /* initialize reject file */
230 init_reject(TMPREJNAME);
232 /* find out where all the lines are */
233 if (!skip_rest_of_patch)
234 scan_input(filearg[0]);
236 /* from here on, open no standard i/o files, because malloc */
237 /* might misfire and we can't catch it easily */
239 /* apply each hunk of patch */
243 while (another_hunk()) {
246 mymaxfuzz = pch_context();
247 if (maxfuzz < mymaxfuzz)
249 if (!skip_rest_of_patch) {
251 where = locate_hunk(fuzz);
252 if (hunk == 1 && where == 0 && !force) {
253 /* dwim for reversed patch? */
256 say("Not enough memory to try swapped hunk! Assuming unswapped.\n");
261 where = locate_hunk(fuzz);
263 /* didn't find it swapped */
265 /* put it back to normal */
266 fatal("lost hunk on alloc error!\n");
268 } else if (noreverse) {
270 /* put it back to normal */
271 fatal("lost hunk on alloc error!\n");
273 say("Ignoring previously applied (or reversed) patch.\n");
274 skip_rest_of_patch = true;
277 say("%seversed (or previously applied) patch detected! %s -R.",
278 reverse ? "R" : "Unr",
279 reverse ? "Assuming" : "Ignoring");
281 ask("%seversed (or previously applied) patch detected! %s -R? [y] ",
282 reverse ? "R" : "Unr",
283 reverse ? "Assume" : "Ignore");
285 ask("Apply anyway? [n] ");
287 skip_rest_of_patch = true;
291 /* put it back to normal */
292 fatal("lost hunk on alloc error!\n");
296 } while (!skip_rest_of_patch && where == 0 &&
297 ++fuzz <= mymaxfuzz);
299 if (skip_rest_of_patch) { /* just got decided */
304 newwhere = pch_newfirst() + last_offset;
305 if (skip_rest_of_patch) {
309 say("Hunk #%d ignored at %ld.\n",
311 } else if (where == 0) {
315 say("Hunk #%d failed at %ld.\n",
320 say("Hunk #%d succeeded at %ld",
323 say(" with fuzz %ld", fuzz);
325 say(" (offset %ld line%s)",
327 last_offset == 1L ? "" : "s");
333 if (out_of_mem && using_plan_a) {
336 say("\n\nRan out of memory using Plan A--trying again...\n\n");
346 fatal("Internal error: hunk should not be 0\n");
348 /* finish spewing out the new file */
349 if (!skip_rest_of_patch)
352 /* and put the output where desired */
354 if (!skip_rest_of_patch) {
356 char *realout = outname;
359 if (move_file(TMPOUTNAME, outname) < 0) {
361 realout = TMPOUTNAME;
362 chmod(TMPOUTNAME, filemode);
364 chmod(outname, filemode);
366 if (remove_empty_files &&
367 stat(realout, &statbuf) == 0 &&
368 statbuf.st_size == 0) {
370 say("Removing %s (empty after patching).\n",
380 if (*rejname == '\0') {
381 if (strlcpy(rejname, outname,
382 sizeof(rejname)) >= sizeof(rejname))
383 fatal("filename %s is too long\n", outname);
384 if (strlcat(rejname, REJEXT,
385 sizeof(rejname)) >= sizeof(rejname))
386 fatal("filename %s is too long\n", outname);
388 if (skip_rest_of_patch) {
389 say("%d out of %d hunks ignored--saving rejects to %s\n",
390 failed, hunk, rejname);
392 say("%d out of %d hunks failed--saving rejects to %s\n",
393 failed, hunk, rejname);
395 if (!check_only && move_file(TMPREJNAME, rejname) < 0)
404 /* Prepare to find the next patch to do in the patch file. */
407 reinitialize_almost_everything(void)
413 last_frozen_line = 0;
430 reverse = reverse_flag_specified;
431 skip_rest_of_patch = false;
436 /* Process switches and filenames. */
439 get_some_switches(void)
441 const char *options = "b::B:cCd:D:eEfF:i:lnNo:p:r:RstuvV:x:z:";
442 static struct option longopts[] = {
443 {"backup", no_argument, 0, 'b'},
444 {"batch", no_argument, 0, 't'},
445 {"check", no_argument, 0, 'C'},
446 {"context", no_argument, 0, 'c'},
447 {"debug", required_argument, 0, 'x'},
448 {"directory", required_argument, 0, 'd'},
449 {"ed", no_argument, 0, 'e'},
450 {"force", no_argument, 0, 'f'},
451 {"forward", no_argument, 0, 'N'},
452 {"fuzz", required_argument, 0, 'F'},
453 {"ifdef", required_argument, 0, 'D'},
454 {"input", required_argument, 0, 'i'},
455 {"ignore-whitespace", no_argument, 0, 'l'},
456 {"normal", no_argument, 0, 'n'},
457 {"output", required_argument, 0, 'o'},
458 {"prefix", required_argument, 0, 'B'},
459 {"quiet", no_argument, 0, 's'},
460 {"reject-file", required_argument, 0, 'r'},
461 {"remove-empty-files", no_argument, 0, 'E'},
462 {"reverse", no_argument, 0, 'R'},
463 {"silent", no_argument, 0, 's'},
464 {"strip", required_argument, 0, 'p'},
465 {"suffix", required_argument, 0, 'z'},
466 {"unified", no_argument, 0, 'u'},
467 {"version", no_argument, 0, 'v'},
468 {"version-control", required_argument, 0, 'V'},
469 {"posix", no_argument, &posix, 1},
479 optreset = optind = 1;
480 while ((ch = getopt_long(Argc, Argv, options, longopts, NULL)) != -1) {
483 if (backup_type == none)
484 backup_type = numbered_existing;
488 say("Warning, the ``-b suffix'' option has been"
489 " obsoleted by the -z option.\n");
492 /* must directly follow 'b' case for backwards compat */
493 simple_backup_suffix = savestr(optarg);
496 origprae = savestr(optarg);
499 diff_type = CONTEXT_DIFF;
505 if (chdir(optarg) < 0)
506 pfatal("can't cd to %s", optarg);
510 if (!isalpha((unsigned char)*optarg) && *optarg != '_')
511 fatal("argument to -D is not an identifier\n");
512 snprintf(if_defined, sizeof if_defined,
513 "#ifdef %s\n", optarg);
514 snprintf(not_defined, sizeof not_defined,
515 "#ifndef %s\n", optarg);
516 snprintf(end_defined, sizeof end_defined,
517 "#endif /* %s */\n", optarg);
523 remove_empty_files = true;
529 maxfuzz = atoi(optarg);
532 if (++filec == MAXFILEC)
533 fatal("too many file arguments\n");
534 filearg[filec] = savestr(optarg);
540 diff_type = NORMAL_DIFF;
546 outname = savestr(optarg);
549 strippath = atoi(optarg);
552 if (strlcpy(rejname, optarg,
553 sizeof(rejname)) >= sizeof(rejname))
554 fatal("argument for -r is too long\n");
558 reverse_flag_specified = true;
567 diff_type = UNI_DIFF;
573 backup_type = get_version(optarg);
577 debug = atoi(optarg);
590 filearg[0] = savestr(*Argv++);
593 if (++filec == MAXFILEC)
594 fatal("too many file arguments\n");
595 filearg[filec] = savestr(*Argv++);
600 if (getenv("POSIXLY_CORRECT") != NULL)
608 "usage: patch [-bCcEeflNnRstuv] [-B backup-prefix] [-D symbol] [-d directory]\n"
609 " [-F max-fuzz] [-i patchfile] [-o out-file] [-p strip-count]\n"
610 " [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n"
611 " [--posix] [origfile [patchfile]]\n"
612 " patch <patchfile\n");
613 my_exit(EXIT_SUCCESS);
617 * Attempt to find the right place to apply this hunk of patch.
620 locate_hunk(LINENUM fuzz)
622 LINENUM first_guess = pch_first() + last_offset;
624 LINENUM pat_lines = pch_ptrn_lines();
625 LINENUM max_pos_offset = input_lines - first_guess - pat_lines + 1;
626 LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + pch_context();
628 if (pat_lines == 0) { /* null range matches always */
629 if (verbose && fuzz == 0 && (diff_type == CONTEXT_DIFF
630 || diff_type == NEW_CONTEXT_DIFF
631 || diff_type == UNI_DIFF)) {
632 say("Empty context always matches.\n");
634 return (first_guess);
636 if (max_neg_offset >= first_guess) /* do not try lines < 0 */
637 max_neg_offset = first_guess - 1;
638 if (first_guess <= input_lines && patch_match(first_guess, 0, fuzz))
640 for (offset = 1; ; offset++) {
641 bool check_after = (offset <= max_pos_offset);
642 bool check_before = (offset <= max_neg_offset);
644 if (check_after && patch_match(first_guess, offset, fuzz)) {
647 say("Offset changing from %ld to %ld\n",
648 last_offset, offset);
650 last_offset = offset;
651 return first_guess + offset;
652 } else if (check_before && patch_match(first_guess, -offset, fuzz)) {
655 say("Offset changing from %ld to %ld\n",
656 last_offset, -offset);
658 last_offset = -offset;
659 return first_guess - offset;
660 } else if (!check_before && !check_after)
665 /* We did not find the pattern, dump out the hunk so they can handle it. */
668 abort_context_hunk(void)
671 const LINENUM pat_end = pch_end();
673 * add in last_offset to guess the same as the previous successful
676 const LINENUM oldfirst = pch_first() + last_offset;
677 const LINENUM newfirst = pch_newfirst() + last_offset;
678 const LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1;
679 const LINENUM newlast = newfirst + pch_repl_lines() - 1;
680 const char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : "");
681 const char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----");
683 fprintf(rejfp, "***************\n");
684 for (i = 0; i <= pat_end; i++) {
685 switch (pch_char(i)) {
687 if (oldlast < oldfirst)
688 fprintf(rejfp, "*** 0%s\n", stars);
689 else if (oldlast == oldfirst)
690 fprintf(rejfp, "*** %ld%s\n", oldfirst, stars);
692 fprintf(rejfp, "*** %ld,%ld%s\n", oldfirst,
696 if (newlast < newfirst)
697 fprintf(rejfp, "--- 0%s\n", minuses);
698 else if (newlast == newfirst)
699 fprintf(rejfp, "--- %ld%s\n", newfirst, minuses);
701 fprintf(rejfp, "--- %ld,%ld%s\n", newfirst,
705 fprintf(rejfp, "%s", pfetch(i));
711 fprintf(rejfp, "%c %s", pch_char(i), pfetch(i));
714 fatal("fatal internal error in abort_context_hunk\n");
720 rej_line(int ch, LINENUM i)
723 const char *line = pfetch(i);
727 fprintf(rejfp, "%c%s", ch, line);
728 if (len == 0 || line[len-1] != '\n')
729 fprintf(rejfp, "\n\\ No newline at end of file\n");
737 const LINENUM pat_end = pch_end();
738 const LINENUM oldfirst = pch_first() + last_offset;
739 const LINENUM newfirst = pch_newfirst() + last_offset;
741 if (diff_type != UNI_DIFF) {
742 abort_context_hunk();
746 for (i = 0; i <= pat_end; i++) {
747 if (pch_char(i) == '=') {
753 fprintf(rejfp, "malformed hunk: no split found\n");
758 fprintf(rejfp, "@@ -%ld,%ld +%ld,%ld @@\n",
759 pch_ptrn_lines() ? oldfirst : 0,
760 pch_ptrn_lines(), newfirst, pch_repl_lines());
761 while (i < split || j <= pat_end) {
762 ch1 = i < split ? pch_char(i) : -1;
763 ch2 = j <= pat_end ? pch_char(j) : -1;
767 } else if (ch1 == ' ' && ch2 == ' ') {
771 } else if (ch1 == '!' && ch2 == '!') {
772 while (i < split && ch1 == '!') {
775 ch1 = i < split ? pch_char(i) : -1;
777 while (j <= pat_end && ch2 == '!') {
780 ch2 = j <= pat_end ? pch_char(j) : -1;
782 } else if (ch1 == '*') {
784 } else if (ch2 == '+' || ch2 == ' ') {
788 fprintf(rejfp, "internal error on (%ld %ld %ld)\n",
797 /* We found where to apply it (we hope), so do it. */
800 apply_hunk(LINENUM where)
803 const LINENUM lastline = pch_ptrn_lines();
804 LINENUM new = lastline + 1;
809 int def_state = OUTSIDE;
810 const LINENUM pat_end = pch_end();
813 while (pch_char(new) == '=' || pch_char(new) == '\n')
816 while (old <= lastline) {
817 if (pch_char(old) == '-') {
818 copy_till(where + old - 1, false);
820 if (def_state == OUTSIDE) {
821 fputs(not_defined, ofp);
822 def_state = IN_IFNDEF;
823 } else if (def_state == IN_IFDEF) {
824 fputs(else_defined, ofp);
827 fputs(pfetch(old), ofp);
831 } else if (new > pat_end) {
833 } else if (pch_char(new) == '+') {
834 copy_till(where + old - 1, false);
836 if (def_state == IN_IFNDEF) {
837 fputs(else_defined, ofp);
839 } else if (def_state == OUTSIDE) {
840 fputs(if_defined, ofp);
841 def_state = IN_IFDEF;
844 fputs(pfetch(new), ofp);
846 } else if (pch_char(new) != pch_char(old)) {
847 say("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
848 pch_hunk_beg() + old,
849 pch_hunk_beg() + new);
851 say("oldchar = '%c', newchar = '%c'\n",
852 pch_char(old), pch_char(new));
855 } else if (pch_char(new) == '!') {
856 copy_till(where + old - 1, false);
858 fputs(not_defined, ofp);
859 def_state = IN_IFNDEF;
861 while (pch_char(old) == '!') {
863 fputs(pfetch(old), ofp);
869 fputs(else_defined, ofp);
872 while (pch_char(new) == '!') {
873 fputs(pfetch(new), ofp);
877 if (pch_char(new) != ' ')
878 fatal("Internal error: expected ' '\n");
881 if (do_defines && def_state != OUTSIDE) {
882 fputs(end_defined, ofp);
887 if (new <= pat_end && pch_char(new) == '+') {
888 copy_till(where + old - 1, false);
890 if (def_state == OUTSIDE) {
891 fputs(if_defined, ofp);
892 def_state = IN_IFDEF;
893 } else if (def_state == IN_IFNDEF) {
894 fputs(else_defined, ofp);
898 while (new <= pat_end && pch_char(new) == '+') {
899 fputs(pfetch(new), ofp);
903 if (do_defines && def_state != OUTSIDE) {
904 fputs(end_defined, ofp);
912 init_output(const char *name)
914 ofp = fopen(name, "w");
916 pfatal("can't create %s", name);
920 * Open a file to put hunks we can't locate.
923 init_reject(const char *name)
925 rejfp = fopen(name, "w");
927 pfatal("can't create %s", name);
931 * Copy input file to output, up to wherever hunk is to be applied.
932 * If endoffile is true, treat the last line specially since it may
936 copy_till(LINENUM lastline, bool endoffile)
938 if (last_frozen_line > lastline)
939 fatal("misordered hunks! output would be garbled\n");
940 while (last_frozen_line < lastline) {
941 if (++last_frozen_line == lastline && endoffile)
942 dump_line(last_frozen_line, !last_line_missing_eol);
944 dump_line(last_frozen_line, true);
949 * Finish copying the input file to the output file.
956 say("il=%ld lfl=%ld\n", input_lines, last_frozen_line);
959 copy_till(input_lines, true); /* dump remainder of file */
965 * Copy one line from input to output.
968 dump_line(LINENUM line, bool write_newline)
975 /* Note: string is not NUL terminated. */
976 for (; *s != '\n'; s++)
983 * Does the patch pattern match at line base+offset?
986 patch_match(LINENUM base, LINENUM offset, LINENUM fuzz)
988 LINENUM pline = 1 + fuzz;
990 LINENUM pat_lines = pch_ptrn_lines() - fuzz;
991 const char *ilineptr;
992 const char *plineptr;
995 for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) {
996 ilineptr = ifetch(iline, offset >= 0);
997 if (ilineptr == NULL)
999 plineptr = pfetch(pline);
1000 plinelen = pch_line_len(pline);
1002 if (!similar(ilineptr, plineptr, plinelen))
1004 } else if (strnNE(ilineptr, plineptr, plinelen))
1006 if (iline == input_lines) {
1008 * We are looking at the last line of the file.
1009 * If the file has no eol, the patch line should
1010 * not have one either and vice-versa. Note that
1013 if (last_line_missing_eol) {
1014 if (plineptr[plinelen - 1] == '\n')
1017 if (plineptr[plinelen - 1] != '\n')
1026 * Do two lines match with canonicalized white space?
1029 similar(const char *a, const char *b, int len)
1032 if (isspace((unsigned char)*b)) { /* whitespace (or \n) to match? */
1033 if (!isspace((unsigned char)*a)) /* no corresponding whitespace? */
1035 while (len && isspace((unsigned char)*b) && *b != '\n')
1036 b++, len--; /* skip pattern whitespace */
1037 while (isspace((unsigned char)*a) && *a != '\n')
1038 a++; /* skip target whitespace */
1039 if (*a == '\n' || *b == '\n')
1040 return (*a == *b); /* should end in sync */
1041 } else if (*a++ != *b++) /* match non-whitespace chars */
1044 len--; /* probably not necessary */
1046 return true; /* actually, this is not reached */
1047 /* since there is always a \n */