[gnome-autoar] Prevent using AUTOAR_*_LAST constant outside autoar-format-filter.[ch]
- From: Ting-Wei Lan <lantw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-autoar] Prevent using AUTOAR_*_LAST constant outside autoar-format-filter.[ch]
- Date: Fri, 6 Sep 2013 10:22:39 +0000 (UTC)
commit 3defbdd1594ff2a8d1c1fa7a523f6cf77d8f697a
Author: Ting-Wei Lan <lantw44 gmail com>
Date: Fri Sep 6 18:19:55 2013 +0800
Prevent using AUTOAR_*_LAST constant outside autoar-format-filter.[ch]
gnome-autoar/autoar-format-filter.c | 44 ++++++++++++++++++++++------------
gnome-autoar/autoar-format-filter.h | 2 +
gnome-autoar/autoar-gtk.c | 10 ++++---
gnome-autoar/autoar-pref.c | 4 +-
4 files changed, 38 insertions(+), 22 deletions(-)
---
diff --git a/gnome-autoar/autoar-format-filter.c b/gnome-autoar/autoar-format-filter.c
index 3010664..97e0233 100644
--- a/gnome-autoar/autoar-format-filter.c
+++ b/gnome-autoar/autoar-format-filter.c
@@ -104,6 +104,12 @@ static AutoarFilterDescription autoar_filter_description[] = {
"application/x-lrzip", "Long Range ZIP (lrzip)" }
};
+AutoarFormat
+autoar_format_last (void)
+{
+ return AUTOAR_FORMAT_LAST;
+}
+
gboolean
autoar_format_is_valid (AutoarFormat format)
{
@@ -113,28 +119,28 @@ autoar_format_is_valid (AutoarFormat format)
const char*
autoar_format_get_mime_type (AutoarFormat format)
{
- g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ g_return_val_if_fail (autoar_format_is_valid (format) , NULL);
return autoar_format_description[format - 1].mime_type;
}
const char*
autoar_format_get_extension (AutoarFormat format)
{
- g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ g_return_val_if_fail (autoar_format_is_valid (format), NULL);
return autoar_format_description[format - 1].extension;
}
const char*
autoar_format_get_description (AutoarFormat format)
{
- g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ g_return_val_if_fail (autoar_format_is_valid (format), NULL);
return autoar_format_description[format - 1].description;
}
int
autoar_format_get_format_libarchive (AutoarFormat format)
{
- g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, -1);
+ g_return_val_if_fail (autoar_format_is_valid (format), -1);
return autoar_format_description[format - 1].libarchive_format;
}
@@ -144,7 +150,7 @@ autoar_format_get_description_libarchive (AutoarFormat format)
struct archive* a;
gchar *str;
- g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ g_return_val_if_fail (autoar_format_is_valid (format), NULL);
a = archive_write_new ();
archive_write_set_format (a, autoar_format_description[format - 1].libarchive_format);
@@ -154,6 +160,12 @@ autoar_format_get_description_libarchive (AutoarFormat format)
return str;
}
+AutoarFilter
+autoar_filter_last (void)
+{
+ return AUTOAR_FILTER_LAST;
+}
+
gboolean
autoar_filter_is_valid (AutoarFilter filter)
{
@@ -163,28 +175,28 @@ autoar_filter_is_valid (AutoarFilter filter)
const char*
autoar_filter_get_mime_type (AutoarFilter filter)
{
- g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
return autoar_filter_description[filter - 1].mime_type;
}
const char*
autoar_filter_get_extension (AutoarFilter filter)
{
- g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
return autoar_filter_description[filter - 1].extension;
}
const char*
autoar_filter_get_description (AutoarFilter filter)
{
- g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
return autoar_filter_description[filter - 1].description;
}
int
autoar_filter_get_filter_libarchive (AutoarFilter filter)
{
- g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, -1);
+ g_return_val_if_fail (autoar_filter_is_valid (filter), -1);
return autoar_filter_description[filter - 1].libarchive_filter;
}
@@ -194,7 +206,7 @@ autoar_filter_get_description_libarchive (AutoarFilter filter)
struct archive *a;
gchar *str;
- g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
a = archive_write_new ();
archive_write_add_filter (a, autoar_filter_description[filter - 1].libarchive_filter);
@@ -208,8 +220,8 @@ gchar*
autoar_format_filter_get_mime_type (AutoarFormat format,
AutoarFilter filter)
{
- g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
- g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ g_return_val_if_fail (autoar_format_is_valid (format), NULL);
+ g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
switch (filter) {
case AUTOAR_FILTER_NONE:
@@ -235,8 +247,8 @@ gchar*
autoar_format_filter_get_extension (AutoarFormat format,
AutoarFilter filter)
{
- g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
- g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ g_return_val_if_fail (autoar_format_is_valid (format), NULL);
+ g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
return g_strconcat (".",
autoar_format_description[format - 1].extension,
@@ -252,8 +264,8 @@ autoar_format_filter_get_description (AutoarFormat format,
gchar *mime_type;
gchar *description;
- g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
- g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ g_return_val_if_fail (autoar_format_is_valid (format), NULL);
+ g_return_val_if_fail (autoar_filter_is_valid (filter), NULL);
mime_type = autoar_format_filter_get_mime_type (format, filter);
description = g_content_type_get_description (mime_type);
diff --git a/gnome-autoar/autoar-format-filter.h b/gnome-autoar/autoar-format-filter.h
index 9449f7e..2175936 100644
--- a/gnome-autoar/autoar-format-filter.h
+++ b/gnome-autoar/autoar-format-filter.h
@@ -62,6 +62,7 @@ typedef enum {
AUTOAR_FILTER_LAST /*< skip >*/
} AutoarFilter;
+AutoarFormat autoar_format_last (void);
gboolean autoar_format_is_valid (AutoarFormat format);
const char *autoar_format_get_mime_type (AutoarFormat format);
const char *autoar_format_get_extension (AutoarFormat format);
@@ -69,6 +70,7 @@ const char *autoar_format_get_description (AutoarFormat format);
int autoar_format_get_format_libarchive (AutoarFormat format);
gchar *autoar_format_get_description_libarchive (AutoarFormat format);
+AutoarFilter autoar_filter_last (void);
gboolean autoar_filter_is_valid (AutoarFilter filter);
const char *autoar_filter_get_mime_type (AutoarFilter filter);
const char *autoar_filter_get_extension (AutoarFilter filter);
diff --git a/gnome-autoar/autoar-gtk.c b/gnome-autoar/autoar-gtk.c
index 38cba8d..ab9dc1c 100644
--- a/gnome-autoar/autoar-gtk.c
+++ b/gnome-autoar/autoar-gtk.c
@@ -358,10 +358,11 @@ static GtkTreeModel*
advanced_format_store (void)
{
GtkListStore *store;
- int i;
+ int i, last;
store = gtk_list_store_new (N_ADVANCED_FORMAT_COLS, G_TYPE_INT, G_TYPE_STRING);
- for (i = 1; i < AUTOAR_FORMAT_LAST; i++) {
+ last = autoar_format_last ();
+ for (i = 1; i < last; i++) {
GtkTreeIter iter;
const char *description;
@@ -379,10 +380,11 @@ static GtkTreeModel*
advanced_filter_store (void)
{
GtkListStore *store;
- int i;
+ int i, last;
store = gtk_list_store_new (N_ADVANCED_FILTER_COLS, G_TYPE_INT, G_TYPE_STRING);
- for (i = 1; i < AUTOAR_FILTER_LAST; i++) {
+ last = autoar_filter_last ();
+ for (i = 1; i < last; i++) {
GtkTreeIter iter;
const char *description;
diff --git a/gnome-autoar/autoar-pref.c b/gnome-autoar/autoar-pref.c
index ed563bc..ae353ab 100644
--- a/gnome-autoar/autoar-pref.c
+++ b/gnome-autoar/autoar-pref.c
@@ -201,7 +201,7 @@ autoar_pref_set_default_format (AutoarPref *arpref,
AutoarFormat format)
{
g_return_if_fail (AUTOAR_IS_PREF (arpref));
- g_return_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST);
+ g_return_if_fail (autoar_format_is_valid (format));
if (arpref->priv->modification_enabled && format != arpref->priv->default_format)
arpref->priv->modification_flags |= MODIFIED_DEFAULT_FORMAT;
arpref->priv->default_format = format;
@@ -212,7 +212,7 @@ autoar_pref_set_default_filter (AutoarPref *arpref,
AutoarFilter filter)
{
g_return_if_fail (AUTOAR_IS_PREF (arpref));
- g_return_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST);
+ g_return_if_fail (autoar_filter_is_valid (filter));
if (arpref->priv->modification_enabled && filter != arpref->priv->default_filter)
arpref->priv->modification_flags |= MODIFIED_DEFAULT_FILTER;
arpref->priv->default_filter = filter;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]