Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Jul 2010 06:53:47 GMT
From:      Benjamin Fiedler <bfiedler@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 180366 for review
Message-ID:  <201007010653.o616rlNR060013@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007010653.o616rlNR060013>