This is a discussion on Re: patch(1) w/paths containing spaces within the mailing.openbsd.tech forums, part of the OpenBSD category; --> On Tue, 26 Oct 2004, Kurt Miller wrote: > From: "Otto Moerbeek" <otto@drijf.net> > > I have this diff ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Tue, 26 Oct 2004, Kurt Miller wrote: > From: "Otto Moerbeek" <otto@drijf.net> > > I have this diff in my tree, which is supposed to handle any funny > > character in pathnames _except_ tabs. I was not able to find a simple, > > robust way to handle tabs. > > Your diff is working fine for my purposes. It improves patch(1) > functionality and will fall back to the old behavior if no tabs are > found. Who cares about tabs anyway? > > Your diff combined with my update-patches diff makes the ports > infrastructure work for creating and applying patches against > paths that contain spaces or other funky chars (except tabs). The > current port I'm working on needs this, but is easy to work around > without it. > > -Kurt Here's a slightly optimized version, based on Jared's proposal, should have the same behaviour as my original diff, please check, -Otto Index: util.c ================================================== ================= RCS file: /cvs/src/usr.bin/patch/util.c,v retrieving revision 1.28 diff -u -p -r1.28 util.c --- util.c 5 Aug 2004 21:47:24 -0000 1.28 +++ util.c 29 Oct 2004 13:19:32 -0000 @@ -333,7 +333,7 @@ char * fetchname(const char *at, bool *exists, int strip_leading) { char *fullname, *name, *t; - int sleading; + int sleading, tab; struct stat filestat; if (at == NULL || *at == '\0') @@ -349,8 +349,10 @@ fetchname(const char *at, bool *exists, return NULL; name = fullname = t = savestr(at); + tab = strchr(t, '\t') != NULL; /* Strip off up to `strip_leading' path components and NUL terminate. */ - for (sleading = strip_leading; *t != '\0' && !isspace(*t); t++) { + for (sleading = strip_leading; *t != '\0' && ((tab && *t != '\t') || + !isspace(*t)); t++) { if (t[0] == '/' && t[1] != '/' && t[1] != '\0') if (--sleading >= 0) name = t + 1; |