summaryrefslogtreecommitdiffstats
path: root/source/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-11-23 21:46:53 +0000
committerJeremy Allison <jra@samba.org>1998-11-23 21:46:53 +0000
commit749c2b691450146c54449772b69f61e0aa34b8b6 (patch)
tree47e013098b995188f57cd26b936e443d96f41675 /source/lib
parentc54bd16ccabff81eb8dd75e8eeaef3749ddfe97f (diff)
downloadsamba-749c2b691450146c54449772b69f61e0aa34b8b6.tar.gz
samba-749c2b691450146c54449772b69f61e0aa34b8b6.tar.xz
samba-749c2b691450146c54449772b69f61e0aa34b8b6.zip
Changed samba.anu.edu.au -> samba.org
Added Andrew's all_string_sub changes. Jeremy.
Diffstat (limited to 'source/lib')
-rw-r--r--source/lib/access.c2
-rw-r--r--source/lib/snprintf.c2
-rw-r--r--source/lib/util_str.c72
3 files changed, 55 insertions, 21 deletions
diff --git a/source/lib/access.c b/source/lib/access.c
index 31f9db4e554..0fa383d84a5 100644
--- a/source/lib/access.c
+++ b/source/lib/access.c
@@ -5,7 +5,7 @@
The code is used here with permission.
The code has been considerably changed from the original. Bug reports
- should be sent to samba-bugs@samba.anu.edu.au
+ should be sent to samba-bugs@samba.org
*/
#include "includes.h"
diff --git a/source/lib/snprintf.c b/source/lib/snprintf.c
index f69c5ca32e4..8bbc67a3b63 100644
--- a/source/lib/snprintf.c
+++ b/source/lib/snprintf.c
@@ -45,7 +45,7 @@
* missing. Some systems only have snprintf() but not vsnprintf(), so
* the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
*
- * Andrew Tridgell (tridge@samba.anu.edu.au) Oct 1998
+ * Andrew Tridgell (tridge@samba.org) Oct 1998
* fixed handling of %.0f
* added test for HAVE_LONG_DOUBLE
*
diff --git a/source/lib/util_str.c b/source/lib/util_str.c
index c943a854cfa..5935533ceeb 100644
--- a/source/lib/util_str.c
+++ b/source/lib/util_str.c
@@ -990,6 +990,7 @@ BOOL string_set(char **dest,const char *src)
return(string_init(dest,src));
}
+
/****************************************************************************
substitute a string for a pattern in another string. Make sure there is
enough room!
@@ -997,31 +998,64 @@ enough room!
This routine looks for pattern in s and replaces it with
insert. It may do multiple replacements.
-return True if a substitution was done.
+any of " ; ' or ` in the insert string are replaced with _
****************************************************************************/
-BOOL string_sub(char *s,const char *pattern,const char *insert)
+void string_sub(char *s,const char *pattern,const char *insert)
{
- BOOL ret = False;
- char *p;
- size_t ls,lp,li;
+ char *p;
+ size_t ls,lp,li, i;
+
+ if (!insert || !pattern || !s) return;
+
+ ls = strlen(s);
+ lp = strlen(pattern);
+ li = strlen(insert);
+
+ if (!*pattern) return;
+
+ while (lp <= ls && (p = strstr(s,pattern))) {
+ memmove(p+li,p+lp,ls + 1 - (PTR_DIFF(p,s) + lp));
+ for (i=0;i<li;i++) {
+ switch (insert[i]) {
+ case '`':
+ case '"':
+ case '\'':
+ case ';':
+ p[i] = '_';
+ break;
+ default:
+ p[i] = insert[i];
+ }
+ }
+ s = p + li;
+ ls += (li-lp);
+ }
+}
- if (!insert || !pattern || !s) return(False);
- ls = strlen(s);
- lp = strlen(pattern);
- li = strlen(insert);
+/****************************************************************************
+similar to string_sub() but allows for any character to be substituted.
+Use with caution!
+****************************************************************************/
+void all_string_sub(char *s,const char *pattern,const char *insert)
+{
+ char *p;
+ size_t ls,lp,li, i;
- if (!*pattern) return(False);
+ if (!insert || !pattern || !s) return;
- while (lp <= ls && (p = strstr(s,pattern)))
- {
- ret = True;
- memmove(p+li,p+lp,ls + 1 - (PTR_DIFF(p,s) + lp));
- memcpy(p,insert,li);
- s = p + li;
- ls = strlen(s);
- }
- return(ret);
+ ls = strlen(s);
+ lp = strlen(pattern);
+ li = strlen(insert);
+
+ if (!*pattern) return;
+
+ while (lp <= ls && (p = strstr(s,pattern))) {
+ memmove(p+li,p+lp,ls + 1 - (PTR_DIFF(p,s) + lp));
+ memcpy(p, insert, li);
+ s = p + li;
+ ls += (li-lp);
+ }
}
/****************************************************************************