]> Pileus Git - lackey/commitdiff
Add string copy and match functions
authorAndy Spencer <andy753421@gmail.com>
Sat, 8 Jun 2013 01:01:07 +0000 (01:01 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 10 Jun 2013 04:54:02 +0000 (04:54 +0000)
src/util.c
src/util.h
src/view.c
views/week.c

index 420dbd56dd99b7279bcd0f21639859d2981c30e4..197f3d8ea17ca09f95b485701357d296feb1190c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
+ * Copyright (C) 2012,2013 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,6 +15,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define _XOPEN_SOURCE
+#define _XOPEN_SOURCE_EXTENDED
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -81,6 +84,22 @@ void strsub(char *str, char find, char repl)
                        *cur = repl;
 }
 
+char *strcopy(const char *str)
+{
+       if (str == NULL)
+               return NULL;
+       return strdup(str);
+}
+
+int match(const char *a, const char *b)
+{
+       if (a == b)
+               return 1;
+       if (!a || !b)
+               return 0;
+       return !strcmp(a, b);
+}
+
 /* Memory functions */
 void *alloc0(int size)
 {
index d0baa3b37e28a7010eca8ff4ef0ddc4948114396..5427686279adb96a26b812d826854376bd88f195 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
+ * Copyright (C) 2012,2013 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,6 +29,8 @@ void util_init(void);
 
 /* Stirng functions */
 void strsub(char *str, char find, char repl);
+char *strcopy(const char *str);
+int match(const char *a, const char *b);
 
 /* Memory functions */
 void *alloc0(int size);
index 6aa6f70126364436dfafcc68d53d2374a7de6f08..691154d07481d724cee3b01f06062e5d9e523bc4 100644 (file)
@@ -75,9 +75,9 @@ static void draw_header(void)
 static int get_color(const char *cat)
 {
        return cat == NULL           ? 0           :
-              !strcmp(cat, "class") ? COLOR_CLASS :
-              !strcmp(cat, "ec")    ? COLOR_EC    :
-              !strcmp(cat, "work")  ? COLOR_WORK  : COLOR_OTHER ;
+              match(cat, "class") ? COLOR_CLASS :
+              match(cat, "ec")    ? COLOR_EC    :
+              match(cat, "work")  ? COLOR_WORK  : COLOR_OTHER ;
 }
 
 /* Helper functions */
index 414c35450b4c3a0e16e7f29b00b801665fe133c6..b8b512730601ed8fbf38098b144bd671174e0fa7 100644 (file)
@@ -17,7 +17,6 @@
 
 #define _XOPEN_SOURCE_EXTENDED
 
-#include <string.h>
 #include <ncurses.h>
 
 #include "util.h"