Mercurial > hg > toybox
comparison toys/patch.c @ 412:2b521c791e4e
Patch shouldn't be bothered by DOS newlines.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 22 Jan 2012 22:28:04 -0600 |
parents | 56d07d82e691 |
children | cd70270dbc51 |
comparison
equal
deleted
inserted
replaced
411:7da386057101 | 412:2b521c791e4e |
---|---|
236 // state 2: In hunk: counting initial context lines | 236 // state 2: In hunk: counting initial context lines |
237 // state 3: In hunk: getting body | 237 // state 3: In hunk: getting body |
238 | 238 |
239 void patch_main(void) | 239 void patch_main(void) |
240 { | 240 { |
241 int reverse = toys.optflags & FLAG_REVERSE, state = 0; | 241 int reverse = toys.optflags&FLAG_REVERSE, state = 0, patchlinenum = 0, |
242 strip = 0; | |
242 char *oldname = NULL, *newname = NULL; | 243 char *oldname = NULL, *newname = NULL; |
243 | 244 |
244 if (TT.infile) TT.filepatch = xopen(TT.infile, O_RDONLY); | 245 if (TT.infile) TT.filepatch = xopen(TT.infile, O_RDONLY); |
245 TT.filein = TT.fileout = -1; | 246 TT.filein = TT.fileout = -1; |
246 | 247 |
247 // Loop through the lines in the patch | 248 // Loop through the lines in the patch |
248 for(;;) { | 249 for (;;) { |
249 char *patchline; | 250 char *patchline; |
250 | 251 |
251 patchline = get_line(TT.filepatch); | 252 patchline = get_line(TT.filepatch); |
252 if (!patchline) break; | 253 if (!patchline) break; |
253 | 254 |
254 // Other versions of patch accept damaged patches, | 255 // Other versions of patch accept damaged patches, |
255 // so we need to also. | 256 // so we need to also. |
257 if (strip || !patchlinenum++) { | |
258 int len = strlen(patchline); | |
259 if (patchline[len-1] == '\r') { | |
260 if (!strip) fdprintf(2, "Removing DOS newlines\n"); | |
261 strip = 1; | |
262 patchline[len-1]=0; | |
263 } | |
264 } | |
256 if (!*patchline) { | 265 if (!*patchline) { |
257 free(patchline); | 266 free(patchline); |
258 patchline = xstrdup(" "); | 267 patchline = xstrdup(" "); |
259 } | 268 } |
260 | 269 |