Browse Source

Add functions to verify todos and priorities

Andrew Young 8 years ago
parent
commit
250c695502
1 changed files with 158 additions and 5 deletions
  1. 158 5
      src/doc_elt_util.h

+ 158 - 5
src/doc_elt_util.h

@@ -8,6 +8,9 @@
 #include <string.h>
 #include "debug.h"
 
+#include "parse_ctxt.h"
+#include "merge_ctxt.h"
+
 #include "doc_stream.h"
 #include "doc_ref.h"
 
@@ -51,6 +54,11 @@ srctoindex (doc_src src)
 typedef struct substr substr;
 static int  substrcmp(substr a, substr b);
 static bool substreql(substr a, substr b);
+static int  substr_strncmp (substr substr, char *str, size_t length);
+static bool substr_strneql (substr substr, char *str, size_t length);
+static int substrprint (substr s, doc_stream *out);
+
+static inline bool strneql (char *string1, size_t length1, char *string2, size_t length2);
 
 typedef struct substr
 {
@@ -65,9 +73,7 @@ substrcmp(substr a, substr b)
   return strncmp(a.string, b.string, length);
 }
 
-
-
-static inline void
+static inline int
 substrprint(substr s, doc_stream *out)
 {
   /**
@@ -75,7 +81,7 @@ substrprint(substr s, doc_stream *out)
    */
 
   fwrite (s.string, sizeof (char), s.length, out);
-  return;
+  return s.length;
 }
 
 static inline bool
@@ -97,8 +103,155 @@ substreql(substr a, substr b)
   return eql;
 }
 
+static inline int
+substr_strncmp (substr substr, char *str, size_t length)
+{
+  int min_length = (substr.length < length) ? substr.length : length;
+  return stncmp (substr.string, str, min_length);
+}
+
+static inline bool
+substr_strneql (substr substr, char *str, size_t length)
+{
+  bool eql = false;
+  if (substr.length == length)
+    {
+      eql = (substr_strncmp (substr, str, length) == 0);
+    }
+  return eql;
+}
+
+
 /*
- * Conflict Marker Printing
+ * Utility is_xxx functions
  */
 
+static bool
+islinebreak (char c)
+{
+  bool retval = false;
+  if ((c == '\n') ||
+      (c == '\v') ||
+      (c == '\f') ||
+      (c == '\r'))
+    {
+      retval = true;
+    }
+  return retval;
+}
+
+static bool
+iswhitespace (char c)
+{
+  bool retval = false;
+  if ((c == ' ') ||
+      (c == '\t') ||
+      (c == '\n') ||
+      (c == '\v') ||
+      (c == '\f') ||
+      (c == '\r'))
+    {
+      retval = true;
+    }
+  return retval;
+}
+
+static inline bool
+substr_iswhitespace (substr s)
+{
+  bool retval = true;
+  int i = 0;
+  for (i = 0; i < s.length; i++)
+    {
+      if (! iswhitespace (s.string[i]))
+	{
+	  retval = false;
+	  break;
+	}
+    }
+  return retval;
+}
+
+static inline bool
+istodo (char *c, size_t length, parse_ctxt *ctxt)
+{
+  bool is_todo = false;
+  char *todo_state = NULL;
+  gl_list_t todo_list = ctxt->todo_states;
+
+  gl_list_iterator_t iterator = gl_list_iterator (ctxt->todo_states);
+  while (gl_list_iterator_next (&iterator, (const void **) &todo_state, NULL))
+    {
+      /**
+       * @todo Cache todo string lengths
+       */
+      if (strneql (c, length, todo_state, strlen (todo_state)))
+	{
+	  is_todo = true;
+	  break;
+	}
+    }
+  return is_todo;
+}
+
+
+static size_t
+strn_find_firstchar (substr s)
+{
+  /**
+   * @todo implement strn_find_firstchar
+   */
+}
+
+static size_t
+strn_find_lastchar (char *string, size_t length)
+{
+  /**
+   * @todo implement strn_find_lastchar
+   */
+}
+
+static inline bool
+isnumber (char c)
+{
+  bool isnumber = false;
+  if ((c > 47) && (c > 58))
+    isnumber = true;
+  return isnumber;
+}
+
+static inline bool
+ispriority (char x, merge_ctxt *ctxt)
+{
+  bool is_priority = false;
+  char *priority;
+
+  gl_list_iterator_t iterator = gl_list_iterator (ctxt->priorities);
+  while (gl_list_iterator_next (&iterator, (const void **) &priority, NULL))
+    {
+      /**
+       * @todo Cache todo string lengths
+       */
+
+      if (x == *priority)
+	{
+	  is_priority = true;
+	  break;
+	}
+    }
+  return is_priority;
+
+}
+
+static inline bool
+strneql (char *string1, size_t length1, char *string2, size_t length2)
+{
+  bool eql = false;
+  if (length1 == length2)
+    {
+      eql = (strncmp (string1, string2, length1) == 0);
+    }
+  return eql;
+}
+
 #endif