]> oss.titaniummirror.com Git - repo_shell.git/commitdiff
stringutils.c collects funcs from several places
authorR. Steve McKown <rsmckown@gmail.com>
Fri, 28 Sep 2012 19:04:21 +0000 (13:04 -0600)
committerR. Steve McKown <rsmckown@gmail.com>
Fri, 28 Sep 2012 19:11:39 +0000 (13:11 -0600)
12 files changed:
Makefile
git_acl.c
git_acl.h
match.c [deleted file]
match.h [deleted file]
mystrtok.c [deleted file]
mystrtok.h [deleted file]
mystrtok_test.c
repo_shell.c
stra.c
stringutils.c [new file with mode: 0644]
stringutils.h [new file with mode: 0644]

index eb4728c21f171ab10bc51fee06ffe4846f193802..d9d1847711cb5221b9444b348dd2282d234addd4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,13 +15,13 @@ PROGRAMS = $(MAIN) mystrtok_test acl_test
 
 all: $(MAIN)
 
-repo_shell: repo_shell.c inih/ini.c git_acl.c mystrtok.c stra.c utility.c match.c version.c
+repo_shell: repo_shell.c inih/ini.c git_acl.c stringutils.c stra.c utility.c version.c
        $(CC) -I inih $^ -o $@
 
-mystrtok_test: mystrtok_test.c mystrtok.c utility.c
+mystrtok_test: mystrtok_test.c stringutils.c utility.c
        $(CC) -g $^ -o $@
 
-acl_test: acl_test.c git_acl.c inih/ini.c mystrtok.c stra.c utility.c match.c
+acl_test: acl_test.c git_acl.c inih/ini.c stringutils.c stra.c utility.c
        $(CC) -I inih $^ -o $@
 
 $(INFILES):%: %.in
index 4bb75ee46fe715788da76b44ae6415db956ffbf7..796f5e96bd935b540e23196780b509917b3a658f 100644 (file)
--- a/git_acl.c
+++ b/git_acl.c
  */
 
 #include <stdbool.h>
-//#include <stdio.h>
-//#include <errno.h>
-//#include <stdlib.h>
-//#include <sys/types.h>
-//#include <fcntl.h>
-//#include <unistd.h>
-//#include <pwd.h>
+#include <stdlib.h>
 #include <string.h>
 #include "ini.h"
 #include "utility.h"
-#include "mystrtok.h"
+#include "stringutils.h"
 #include "stra.h"
-#include "match.h"
 #include "git_acl.h"
 
 enum {
@@ -115,23 +108,6 @@ static acl_clear(acl_t *acl)
   stra_destroy(&acl->userids);
 }
 
-static bool str_has_word(const char* string, const char* word)
-{
-  char *_s = xstrdup(string);
-  char *s = _s;
-  char *p = my_strtok(&s, " \t\n");
-
-  while (p) {
-    if (match(p, word)) {
-      free(_s);
-      return true;
-    }
-    p = my_strtok(&s, " \t\n");
-  }
-  free(_s);
-  return false;
-}
-
 static int acl_handler(void* user, const char* section, const char* name,
     const char* value)
 {
index 47c6aa88af7752b38bc7432e062f7501dde9da01..b1be1653a1c5f3bb2baf1cc1f37051b05c74f0c4 100644 (file)
--- a/git_acl.h
+++ b/git_acl.h
 #ifndef GIT_ACL_H
 #define GIT_ACL_H
 
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <pwd.h>
-#include <string.h>
-#include "ini.h"
-#include "utility.h"
-#include "mystrtok.h"
-#include "stra.h"
-
 typedef enum {
   PERMS_NOTFOUND = 0,
   PERMS_NONE,
diff --git a/match.c b/match.c
deleted file mode 100644 (file)
index 32938a1..0000000
--- a/match.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright © 2012, Titanium Mirror, Inc.
- * All Rights Reserved.
- *
- * This document is the proprietary and confidential property of
- * Titanium Mirror, Inc.  All use, distribution, reproduction or re-distribution
- * is disallowed without the prior express written consent of
- * Titanium Mirror, Inc.
- */
-
-/*
- * Match allowing wildcard ('*')
- *
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-
-#include <stdbool.h>
-#include <string.h>
-
-bool match(const char* pattern, const char* string)
-{
-  char* p;
-
-  if (!pattern || !string)
-    return false;
-  p = index(pattern, '*');
-  if (p == pattern)
-    return true;
-  else if (p)
-    return (strncmp(pattern, string, p - pattern) == 0);
-  else
-    return (strcmp(pattern, string) == 0);
-}
diff --git a/match.h b/match.h
deleted file mode 100644 (file)
index 756d6c6..0000000
--- a/match.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright © 2012, Titanium Mirror, Inc.
- * All Rights Reserved.
- *
- * This document is the proprietary and confidential property of
- * Titanium Mirror, Inc.  All use, distribution, reproduction or re-distribution
- * is disallowed without the prior express written consent of
- * Titanium Mirror, Inc.
- */
-
-/*
- * Match allowing wildcard ('*')
- *
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-
-#ifndef MATCH_H
-#define MATCH_H
-
-#include <stdbool.h>
-
-bool match(const char* pattern, const char* string);
-
-#endif /* end of include guard: MATCH_H */
diff --git a/mystrtok.c b/mystrtok.c
deleted file mode 100644 (file)
index f075683..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright © 2012, Titanium Mirror, Inc.
- * All Rights Reserved.
- *
- * This document is the proprietary and confidential property of
- * Titanium Mirror, Inc.  All use, distribution, reproduction or re-distribution
- * is disallowed without the prior express written consent of
- * Titanium Mirror, Inc.
- */
-
-/*
- * A custom strtok.  This version skips any number and any combination of
- * delimiter characters between tokens.
- *
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-
-#include <stddef.h>
-#include <strings.h>
-
-char *my_strtok(char **begin, char* delims)
-{
-  char *p;
-  char *q;
-
-  if (!begin)
-    return NULL;
-  if (!delims || !*delims || !*begin)
-    return (*begin = NULL);
-
-  q = *begin;
-  while (*q && index(delims, *q)) q++;
-  if (!*q)
-    return (*begin = NULL);
-  p = q;
-  while (*q && !index(delims, *q)) q++;
-  if (*q)
-    *q++ = 0;
-  *begin = q;
-  return p;
-}
diff --git a/mystrtok.h b/mystrtok.h
deleted file mode 100644 (file)
index 6968fa8..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright © 2012, Titanium Mirror, Inc.
- * All Rights Reserved.
- *
- * This document is the proprietary and confidential property of
- * Titanium Mirror, Inc.  All use, distribution, reproduction or re-distribution
- * is disallowed without the prior express written consent of
- * Titanium Mirror, Inc.
- */
-
-/*
- * A custom strtok.  This version skips any number and any combination of
- * delimiter characters between tokens.
- *
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-
-#ifndef MYSTRTOK_H
-#define MYSTRTOK_H
-
-char *my_strtok(char **begin, char* delims);
-
-#endif /* end of include guard: MYSTRTOK_H */
index 5a8756e435c36e4b79661ef29ee40e4b197bd5b7..fa685890a229eea419ba2dc713322ab4f2d832a0 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdio.h>
 #include "utility.h"
-#include "mystrtok.h"
+#include "stringutils.h"
 
 int main(int argc, char **argv)
 {
index 86e27b2b1a096f5758ca2c1b6074ac948dd0cbfb..7ef610d247bf4c22cfd8591de37c93b97f418f99 100644 (file)
@@ -12,6 +12,7 @@
 #include "utility.h"
 #include "version.h"
 #include "git_acl.h"
+#include "stringutils.h"
 
 #define CFG_FILE "/etc/repo_shell.cfg"
 #define SHELL "/bin/bash"
diff --git a/stra.c b/stra.c
index 232419af91fe7a39d9a6ec977147fd3629d44f36..21bceac395a68c4632a6436eae131310c16b98d4 100644 (file)
--- a/stra.c
+++ b/stra.c
@@ -16,8 +16,8 @@
 
 #include <stdlib.h>
 #include "utility.h"
+#include "stringutils.h"
 #include "stra.h"
-#include "match.h"
 
 void stra_init(stra_t *stra, size_t size)
 {
diff --git a/stringutils.c b/stringutils.c
new file mode 100644 (file)
index 0000000..8249d86
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright © 2012, Titanium Mirror, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of
+ * Titanium Mirror, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of
+ * Titanium Mirror, Inc.
+ */
+
+/*
+ * A custom strtok.  This version skips any number and any combination of
+ * delimiter characters between tokens.
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "utility.h"
+
+bool match(const char* pattern, const char* string)
+{
+  char* p;
+
+  if (!pattern || !string)
+    return false;
+  p = index(pattern, '*');
+  if (p == pattern)
+    return true;
+  else if (p)
+    return (strncmp(pattern, string, p - pattern) == 0);
+  else
+    return (strcmp(pattern, string) == 0);
+}
+
+char *my_strtok(char **begin, char* delims)
+{
+  char *p;
+  char *q;
+
+  if (!begin)
+    return NULL;
+  if (!delims || !*delims || !*begin)
+    return (*begin = NULL);
+
+  q = *begin;
+  while (*q && index(delims, *q)) q++;
+  if (!*q)
+    return (*begin = NULL);
+  p = q;
+  while (*q && !index(delims, *q)) q++;
+  if (*q)
+    *q++ = 0;
+  *begin = q;
+  return p;
+}
+
+bool str_has_word(const char* string, const char* word)
+{
+  char *_s = xstrdup(string);
+  char *s = _s;
+  char *p = my_strtok(&s, " \t\n");
+
+  while (p) {
+    if (match(p, word)) {
+      free(_s);
+      return true;
+    }
+    p = my_strtok(&s, " \t\n");
+  }
+  free(_s);
+  return false;
+}
diff --git a/stringutils.h b/stringutils.h
new file mode 100644 (file)
index 0000000..16731dd
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2012, Titanium Mirror, Inc.
+ * All Rights Reserved.
+ *
+ * This document is the proprietary and confidential property of
+ * Titanium Mirror, Inc.  All use, distribution, reproduction or re-distribution
+ * is disallowed without the prior express written consent of
+ * Titanium Mirror, Inc.
+ */
+
+/*
+ * A custom strtok.  This version skips any number and any combination of
+ * delimiter characters between tokens.
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#ifndef MYSTRTOK_H
+#define MYSTRTOK_H
+
+#include <stdbool.h>
+
+/* Return tokens separated by any combination of contiguous characters drawn
+ * from the contents of delims.  begin is the address of the pointer containing
+ * the original string on first call, and is updated during each call to skip
+ * the token already returned.  Returns NULL when no more tokens are available
+ * in the string.  The string pointed to by **begin is altered, as is true also
+ * with the generic strtok().
+ */
+char *my_strtok(char **begin, char* delims);
+
+/* Returns true if the word is contained within string.  Words are delimited by
+ * any whitespace characters.
+ */
+bool str_has_word(const char* string, const char* word);
+
+/* Returns true if the pattern matches string.  Only the asterisk character is
+ * used as a wildcard, meaning zero or more characters of any value.  The
+ * wildcard, if present, may only be the last character in the pattern string.
+ */
+bool match(const char* pattern, const char* string);
+
+#endif /* end of include guard: MYSTRTOK_H */