summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b3f890e)
raw | patch | inline | side by side (parent: b3f890e)
author | Max Kellermann <max@duempel.org> | |
Fri, 8 Nov 2013 17:14:31 +0000 (18:14 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 8 Nov 2013 17:14:31 +0000 (18:14 +0100) |
Makefile.am | patch | blob | history | |
src/Compiler.h | [new file with mode: 0644] | patch | blob |
src/charset.h | patch | blob | history | |
src/colors.h | patch | blob | history | |
src/command.c | patch | blob | history | |
src/command.h | patch | blob | history | |
src/filelist.c | patch | blob | history | |
src/filelist.h | patch | blob | history | |
src/match.h | patch | blob | history | |
src/mpdclient.h | patch | blob | history | |
src/playlist.h | patch | blob | history |
diff --git a/Makefile.am b/Makefile.am
index 1f8e8fea231dd98a302acbd7c34891c395de09d1..72e93a183c1232d744fc41923344d46bbdf8aedf 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
$(LIBLIRCCLIENT_LIBS)
src_ncmpc_SOURCES = \
+ src/Compiler.h \
$(ncmpc_headers) \
src/main.c \
src/gidle.c \
diff --git a/src/Compiler.h b/src/Compiler.h
--- /dev/null
+++ b/src/Compiler.h
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef COMPILER_H
+#define COMPILER_H
+
+#define GCC_CHECK_VERSION(major, minor) \
+ (defined(__GNUC__) && \
+ (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))))
+
+#ifdef __GNUC__
+#define GCC_VERSION (__GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+ + __GNUC_PATCHLEVEL__)
+#else
+#define GCC_VERSION 0
+#endif
+
+#if GCC_CHECK_VERSION(4,0)
+
+/* GCC 4.x */
+
+#define gcc_const __attribute__((const))
+#define gcc_deprecated __attribute__((deprecated))
+#define gcc_may_alias __attribute__((may_alias))
+#define gcc_malloc __attribute__((malloc))
+#define gcc_noreturn __attribute__((noreturn))
+#define gcc_packed __attribute__((packed))
+#define gcc_printf(a,b) __attribute__((format(printf, a, b)))
+#define gcc_pure __attribute__((pure))
+#define gcc_sentinel __attribute__((sentinel))
+#define gcc_unused __attribute__((unused))
+#define gcc_warn_unused_result __attribute__((warn_unused_result))
+
+#define gcc_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
+#define gcc_nonnull_all __attribute__((nonnull))
+
+#define gcc_likely(x) __builtin_expect (!!(x), 1)
+#define gcc_unlikely(x) __builtin_expect (!!(x), 0)
+
+#define gcc_aligned(n) __attribute__((aligned(n)))
+
+#define gcc_visibility_hidden __attribute__((visibility("hidden")))
+#define gcc_visibility_default __attribute__((visibility("default")))
+
+#define gcc_always_inline __attribute__((always_inline))
+
+#else
+
+/* generic C compiler */
+
+#define gcc_const
+#define gcc_deprecated
+#define gcc_may_alias
+#define gcc_malloc
+#define gcc_noreturn
+#define gcc_packed
+#define gcc_printf(a,b)
+#define gcc_pure
+#define gcc_sentinel
+#define gcc_unused
+#define gcc_warn_unused_result
+
+#define gcc_nonnull(...)
+#define gcc_nonnull_all
+
+#define gcc_likely(x) (x)
+#define gcc_unlikely(x) (x)
+
+#define gcc_aligned(n)
+
+#define gcc_visibility_hidden
+#define gcc_visibility_default
+
+#define gcc_always_inline inline
+
+#endif
+
+#if GCC_CHECK_VERSION(4,3)
+
+#define gcc_hot __attribute__((hot))
+#define gcc_cold __attribute__((cold))
+
+#else /* ! GCC_UNUSED >= 40300 */
+
+#define gcc_hot
+#define gcc_cold
+
+#endif /* ! GCC_UNUSED >= 40300 */
+
+#if GCC_CHECK_VERSION(4,6) && !defined(__clang__)
+#define gcc_flatten __attribute__((flatten))
+#else
+#define gcc_flatten
+#endif
+
+#ifndef __cplusplus
+/* plain C99 has "restrict" */
+#define gcc_restrict restrict
+#elif GCC_CHECK_VERSION(4,0)
+/* "__restrict__" is a GCC extension for C++ */
+#define gcc_restrict __restrict__
+#else
+/* disable it on other compilers */
+#define gcc_restrict
+#endif
+
+/* C++11 features */
+
+#if defined(__cplusplus)
+
+/* support for C++11 "override" was added in gcc 4.7 */
+#if !defined(__clang__) && !GCC_CHECK_VERSION(4,7)
+#define override
+#define final
+#endif
+
+#if defined(__clang__) || GCC_CHECK_VERSION(4,8)
+#define gcc_alignas(T, fallback) alignas(T)
+#else
+#define gcc_alignas(T, fallback) gcc_aligned(fallback)
+#endif
+
+#endif
+
+#ifndef __has_feature
+ // define dummy macro for non-clang compilers
+ #define __has_feature(x) 0
+#endif
+
+#if __has_feature(attribute_unused_on_fields)
+#define gcc_unused_field gcc_unused
+#else
+#define gcc_unused_field
+#endif
+
+#if defined(__GNUC__) || defined(__clang__)
+#define gcc_unreachable() __builtin_unreachable()
+#else
+#define gcc_unreachable()
+#endif
+
+#endif
diff --git a/src/charset.h b/src/charset.h
index 1564f3fb750fcae384f56ba154535612afc1f492..1fa5ec4fdac4b289674e0b670b19691cc8598c58 100644 (file)
--- a/src/charset.h
+++ b/src/charset.h
#define CHARSET_H
#include "config.h"
-
-#include <glib.h>
+#include "Compiler.h"
#include <stdbool.h>
/**
* Returns the number of terminal cells occupied by this string.
*/
-G_GNUC_PURE
+gcc_pure
unsigned
utf8_width(const char *str);
/**
* Returns the number of terminal cells occupied by this string.
*/
-G_GNUC_PURE
+gcc_pure
unsigned
locale_width(const char *p);
diff --git a/src/colors.h b/src/colors.h
index f049df8766d1a7c600002f0ebc9e2972dfdf6ec6..4d8e876d1d24f04e8ec2b93e715c13742dd1e145 100644 (file)
--- a/src/colors.h
+++ b/src/colors.h
#include "config.h"
#include "ncmpc_curses.h"
+#include "Compiler.h"
enum color {
COLOR_TITLE = 1,
COLOR_END
};
+gcc_pure
int colors_str2color(const char *str);
#ifdef ENABLE_COLORS
diff --git a/src/command.c b/src/command.c
index b9a909ffef8f982753dc7aa26d3a79d061a84f5a..5621b165650b34fd2197b846755ee3c3967ef242 100644 (file)
--- a/src/command.c
+++ b/src/command.c
}
command_t
-get_key_command_from_name(char *name)
+get_key_command_from_name(const char *name)
{
for (int i = 0; cmds[i].name; i++)
if (strcmp(name, cmds[i].name) == 0)
}
command_t
-find_key_command(int key, command_definition_t *c)
+find_key_command(int key, const command_definition_t *c)
{
assert(key != 0);
assert(c != NULL);
diff --git a/src/command.h b/src/command.h
index 9e8b1664d2475d585be84d71e392753fa26b9d8f..307bba1d8359097882af779df0847b56c6f68a1a 100644 (file)
--- a/src/command.h
+++ b/src/command.h
#define COMMAND_H
#include "config.h"
+#include "Compiler.h"
#include <stddef.h>
#include <stdbool.h>
size_t get_cmds_max_name_width(command_definition_t *cmds);
#endif
-command_t find_key_command(int key, command_definition_t *cmds);
+gcc_pure
+command_t
+find_key_command(int key, const command_definition_t *cmds);
void command_dump_keys(void);
#endif
+gcc_pure
const char *key2str(int key);
+
+gcc_pure
const char *get_key_description(command_t command);
+
+gcc_pure
const char *get_key_command_name(command_t command);
+
+gcc_pure
const char *get_key_names(command_t command, bool all);
+
+gcc_pure
command_t get_key_command(int key);
-command_t get_key_command_from_name(char *name);
+
+gcc_pure
+command_t
+get_key_command_from_name(const char *name);
+
int assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]);
+gcc_pure
command_t get_keyboard_command(void);
#endif
diff --git a/src/filelist.c b/src/filelist.c
index 5138fdbcee86f25d65eb8e0941eb43a6ef2dc172..6a5ade39a06ba90ad14fa7c64760e60141021e95 100644 (file)
--- a/src/filelist.c
+++ b/src/filelist.c
}
int
-filelist_find_song(struct filelist *fl, const struct mpd_song *song)
+filelist_find_song(const struct filelist *fl, const struct mpd_song *song)
{
guint i;
}
int
-filelist_find_directory(struct filelist *filelist, const char *name)
+filelist_find_directory(const struct filelist *filelist, const char *name)
{
guint i;
diff --git a/src/filelist.h b/src/filelist.h
index ad4cbf37fa1dab0778700c0a14f24c6655463137..11faab66c184156d00e23e238abcbb1857c77d64 100644 (file)
--- a/src/filelist.h
+++ b/src/filelist.h
#ifndef FILELIST_H
#define FILELIST_H
+#include "Compiler.h"
+
#include <glib.h>
struct mpd_connection;
return filelist_length(filelist) == 0;
}
+gcc_pure
static inline struct filelist_entry *
filelist_get(const struct filelist *filelist, guint i)
{
void
filelist_move(struct filelist *filelist, struct filelist *from);
+gcc_pure
gint
compare_filelist_entry_path(gconstpointer filelist_entry1,
gconstpointer filelist_entry2);
void
filelist_no_duplicates(struct filelist *filelist);
+gcc_pure
int
-filelist_find_song(struct filelist *flist, const struct mpd_song *song);
+filelist_find_song(const struct filelist *flist, const struct mpd_song *song);
+gcc_pure
int
-filelist_find_directory(struct filelist *filelist, const char *name);
+filelist_find_directory(const struct filelist *filelist, const char *name);
/**
* Receives entities from the connection, and appends them to the
diff --git a/src/match.h b/src/match.h
index 5948ead19c2c519aa26b36dc3275029a71e7962a..d4771ec85e60ad21a195df8143954fa19b54e6cf 100644 (file)
--- a/src/match.h
+++ b/src/match.h
#define MATCH_H
#include "config.h"
+#include "Compiler.h"
#include <stdbool.h>
GRegex *
compile_regex(const char *src, bool anchor);
+gcc_pure
bool
match_regex(GRegex *regex, const char *line);
* Checks whether the specified line matches the search string. Case
* is ignored.
*/
+gcc_pure
bool
match_line(const char *line, const char *needle);
diff --git a/src/mpdclient.h b/src/mpdclient.h
index c2aa377d9db8b80d2f8d18150a397e0a4c0076f7..8dab0936856b06d448e9d363558c01b9e91f5ef1 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
#define MPDCLIENT_H
#include "playlist.h"
+#include "Compiler.h"
#include <mpd/client.h>
void mpdclient_free(struct mpdclient *c);
-G_GNUC_PURE
+gcc_pure
static inline bool
mpdclient_is_connected(const struct mpdclient *c)
{
return c->connection != NULL;
}
-G_GNUC_PURE
+gcc_pure
static inline bool
mpdclient_is_playing(const struct mpdclient *c)
{
mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
}
-G_GNUC_PURE
+gcc_pure
static inline const struct mpd_song *
mpdclient_get_current_song(const struct mpdclient *c)
{
mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
/* sort by list-format */
+gcc_pure
gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
#endif
diff --git a/src/playlist.h b/src/playlist.h
index 00434961e0a44963cb6957d9d59e17e0170edd76..2754afad8793faf1fcc7426669606802c2426e1d 100644 (file)
--- a/src/playlist.h
+++ b/src/playlist.h
#ifndef MPDCLIENT_PLAYLIST_H
#define MPDCLIENT_PLAYLIST_H
+#include "Compiler.h"
+
#include <mpd/client.h>
#include <assert.h>
return playlist_get_index_from_file(playlist, mpd_song_get_uri(song));
}
+gcc_pure
gint
playlist_get_id_from_uri(const struct mpdclient_playlist *playlist,
const gchar *uri);
+gcc_pure
static inline gint
playlist_get_id_from_same_song(const struct mpdclient_playlist *playlist,
const struct mpd_song *song)