Annotation of pkgsrc/devel/cvsdiff2patch/files/cvsdiff2patch.c, revision 1.2
1.2 ! richard 1: /* $NetBSD: cvsdiff2patch.c,v 1.1.1.1 2007/11/29 10:11:13 bjs Exp $ */
1.1 bjs 2:
3: /*
4: * Copyright (c) 2003 Research Engineering Development Inc.
5: * All rights reserved.
6: * Author: Alfred Perlstein <alfred@FreeBSD.org>
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: *
17: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27: * SUCH DAMAGE.
28: *
1.2 ! richard 29: * $Id: cvsdiff2patch.c,v 1.1.1.1 2007/11/29 10:11:13 bjs Exp $
1.1 bjs 30: */
31:
32: /*
33: * Convert crappy CVS diffs into something that patch(1) understands.
34: */
1.2 ! richard 35: #ifdef HAVE_NBCOMPAT_H
! 36: #include <nbcompat/config.h> /* needed for the other headers */
! 37: #include <nbcompat/cdefs.h> /* needed for the other headers */
! 38: #include <nbcompat/stdio.h>
! 39: #include <nbcompat/string.h>
! 40: #include <nbcompat/stdlib.h>
! 41: #include <nbcompat/err.h>
! 42: #else
1.1 bjs 43: #include <stdio.h>
44: #include <string.h>
45: #include <stdlib.h>
46: #include <err.h>
1.2 ! richard 47: #endif
1.1 bjs 48:
49: char * xstrdup(const char *str);
50: int fileline(const char *line, int ch);
51:
52: char *
53: xstrdup(const char *str)
54: {
55: char *ret;
56:
57: ret = strdup(str);
58: if (str == NULL)
59: err(1, "strdup");
60: return (ret);
61: }
62:
63: int
64: fileline(const char *line, int ch)
65: {
66: int i;
67:
68: for (i = 0; i < 3; i++) {
69: if (line[i] != ch)
70: return (0);
71: }
72: if (line[strlen(line) - 1] == ch) {
73: return (0);
74: }
75: return (1);
76: }
77:
78: int
79: main(void)
80: {
81: char *line, *filepath;
82: size_t len;
83: const char *indexstr = "Index:";
84: size_t indexlen;
85:
86: fprintf(stderr,
87: "Cvsdiff2patch (c) 2003 Research Engineering Development\n");
88:
89: filepath = NULL;
90: indexlen = strlen(indexstr);
91:
92: while ((line = fgetln(stdin, &len)) != NULL) {
93: line[len - 1] = '\0';
94: if (len > indexlen && strncmp(line, indexstr, indexlen) == 0) {
95: char *p;
96:
97: p = memchr(line, ' ', len);
98: if (p != NULL) {
99: p++;
100: free(filepath);
101: filepath = xstrdup(p);
102: }
103: continue;
104: }
105: if (len > 4 &&
106: (fileline(line, '-') ||
107: fileline(line, '+') ||
108: fileline(line, '*'))) {
109: line[3] = '\0';
110: printf("%s %s\n", line, filepath);
111: continue;
112: }
113: line[len - 1] = '\n';
114: switch (*line) {
115: case ' ':
116: case '+':
117: case '-':
118: case '!':
119: case '@':
120: case '*':
121: fwrite(line, 1, len, stdout);
122: break;
123: default:
124: #if 0
125: printf("blah! ");
126: fwrite(line, 1, len, stdout);
127: #endif
128: break;
129: }
130: }
131: return (0);
132: }
CVSweb <webmaster@jp.NetBSD.org>