From: Andy Spencer Date: Sat, 8 Jun 2013 01:01:07 +0000 (+0000) Subject: Add string copy and match functions X-Git-Url: http://pileus.org/git/?p=lackey;a=commitdiff_plain;h=cfe3c8f203bd937ca4cadf7ef6c1bd9b2c603e13 Add string copy and match functions --- diff --git a/src/util.c b/src/util.c index 420dbd5..197f3d8 100644 --- a/src/util.c +++ b/src/util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Andy Spencer + * Copyright (C) 2012,2013 Andy Spencer * * 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 . */ +#define _XOPEN_SOURCE +#define _XOPEN_SOURCE_EXTENDED + #include #include #include @@ -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) { diff --git a/src/util.h b/src/util.h index d0baa3b..5427686 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Andy Spencer + * Copyright (C) 2012,2013 Andy Spencer * * 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); diff --git a/src/view.c b/src/view.c index 6aa6f70..691154d 100644 --- a/src/view.c +++ b/src/view.c @@ -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 */ diff --git a/views/week.c b/views/week.c index 414c354..b8b5127 100644 --- a/views/week.c +++ b/views/week.c @@ -17,7 +17,6 @@ #define _XOPEN_SOURCE_EXTENDED -#include #include #include "util.h"