Annotation of pkgsrc/devel/cvsdiff2patch/files/cvsdiff2patch.c, revision 1.1
1.1 ! bjs 1: /* $NetBSD$ */
! 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: *
! 29: * $Id: cvsdiff2patch.c,v 1.1 2003/06/06 16:56:08 bright Exp $
! 30: */
! 31:
! 32: /*
! 33: * Convert crappy CVS diffs into something that patch(1) understands.
! 34: */
! 35:
! 36: #include <stdio.h>
! 37: #include <string.h>
! 38: #include <stdlib.h>
! 39: #include <err.h>
! 40:
! 41: char * xstrdup(const char *str);
! 42: int fileline(const char *line, int ch);
! 43:
! 44: char *
! 45: xstrdup(const char *str)
! 46: {
! 47: char *ret;
! 48:
! 49: ret = strdup(str);
! 50: if (str == NULL)
! 51: err(1, "strdup");
! 52: return (ret);
! 53: }
! 54:
! 55: int
! 56: fileline(const char *line, int ch)
! 57: {
! 58: int i;
! 59:
! 60: for (i = 0; i < 3; i++) {
! 61: if (line[i] != ch)
! 62: return (0);
! 63: }
! 64: if (line[strlen(line) - 1] == ch) {
! 65: return (0);
! 66: }
! 67: return (1);
! 68: }
! 69:
! 70: int
! 71: main(void)
! 72: {
! 73: char *line, *filepath;
! 74: size_t len;
! 75: const char *indexstr = "Index:";
! 76: size_t indexlen;
! 77:
! 78: fprintf(stderr,
! 79: "Cvsdiff2patch (c) 2003 Research Engineering Development\n");
! 80:
! 81: filepath = NULL;
! 82: indexlen = strlen(indexstr);
! 83:
! 84: while ((line = fgetln(stdin, &len)) != NULL) {
! 85: line[len - 1] = '\0';
! 86: if (len > indexlen && strncmp(line, indexstr, indexlen) == 0) {
! 87: char *p;
! 88:
! 89: p = memchr(line, ' ', len);
! 90: if (p != NULL) {
! 91: p++;
! 92: free(filepath);
! 93: filepath = xstrdup(p);
! 94: }
! 95: continue;
! 96: }
! 97: if (len > 4 &&
! 98: (fileline(line, '-') ||
! 99: fileline(line, '+') ||
! 100: fileline(line, '*'))) {
! 101: line[3] = '\0';
! 102: printf("%s %s\n", line, filepath);
! 103: continue;
! 104: }
! 105: line[len - 1] = '\n';
! 106: switch (*line) {
! 107: case ' ':
! 108: case '+':
! 109: case '-':
! 110: case '!':
! 111: case '@':
! 112: case '*':
! 113: fwrite(line, 1, len, stdout);
! 114: break;
! 115: default:
! 116: #if 0
! 117: printf("blah! ");
! 118: fwrite(line, 1, len, stdout);
! 119: #endif
! 120: break;
! 121: }
! 122: }
! 123: return (0);
! 124: }
CVSweb <webmaster@jp.NetBSD.org>