From owner-p4-projects@FreeBSD.ORG Thu Jul 1 06:53:47 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8BA941065673; Thu, 1 Jul 2010 06:53:47 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4EA151065670 for ; Thu, 1 Jul 2010 06:53:47 +0000 (UTC) (envelope-from bfiedler@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 23EC28FC0A for ; Thu, 1 Jul 2010 06:53:47 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o616rlB0060015 for ; Thu, 1 Jul 2010 06:53:47 GMT (envelope-from bfiedler@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o616rlNR060013 for perforce@freebsd.org; Thu, 1 Jul 2010 06:53:47 GMT (envelope-from bfiedler@FreeBSD.org) Date: Thu, 1 Jul 2010 06:53:47 GMT Message-Id: <201007010653.o616rlNR060013@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bfiedler@FreeBSD.org using -f From: Benjamin Fiedler To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 180366 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jul 2010 06:53:47 -0000 http://p4web.freebsd.org/@@180366?ac=10 Change 180366 by bfiedler@freebsd-home on 2010/07/01 06:53:32 Add prototype strrep() func; squelch errors on sdiff build Affected files ... .. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#7 edit .. //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#8 edit .. //depot/projects/soc2010/bsdtextproc/sdiff/common.c#2 edit Differences ... ==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#7 (text+ko) ==== @@ -95,6 +95,7 @@ extern regex_t ignore_re; char *splice(char *, char *); +char *strrep(char*, char*, char*); int diffreg(char *, char *, int); int easprintf(char **, const char *, ...); void *emalloc(size_t); ==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#8 (text+ko) ==== @@ -1570,3 +1570,67 @@ } + +/* + * Replaces all occurences of substring 'old' with substring 'new', + * realloc()'ing base ptr as necessary + */ +char * +strrep(char *base, char *old, char *new) +{ + char *ptr, *tmp, *end; + int occ, len1, len2, newlen; + + occ = 0; + ptr = base; + + len1 = strlen(old); + len2 = strlen(new); + + if( len1 == 0 ) + { + return base; + } + + while( (ptr = strstr(ptr, old)) ) + { + occ++; + ptr+=len1; + } + + if( occ == 0){ + return base; + } + + + newlen = strlen(base) + occ * (len2 - len1); + end = base + newlen -1; + if( len2 > len1) + { + base = realloc(base, sizeof(char) * newlen ); + } + + tmp = malloc( sizeof(char) * strlen(base)); + + if( len2 > 0 ) + { + len2 = 1; + } + for (ptr = base; (ptr = strstr(base, old)) != NULL; ) + { + strncpy(tmp, ptr+len1, strlen(base) ); + strncpy(ptr, new, len2); + strncpy(ptr+len2, tmp, end - ptr ); + ptr+=len2; + } + + if(len2 < len1) + { + *(end + occ*(len2 - len1) ) = '\0'; + } + + free(tmp); + + return base; +} + ==== //depot/projects/soc2010/bsdtextproc/sdiff/common.c#2 (text+ko) ==== @@ -11,7 +11,7 @@ #include "common.h" -void +__dead void cleanup(const char *filename) { if (unlink(filename))