From 8abdea27b4b1df17f6623373d6ae24ad05bc871f Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Thu, 13 Nov 2008 15:55:15 +0100 Subject: Create a macro to easily add some checks. --- src/cups.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/cups.c b/src/cups.c index d817256..597cb4c 100644 --- a/src/cups.c +++ b/src/cups.c @@ -222,6 +222,24 @@ _cph_cups_is_string_printable (const char *str) return TRUE; } +#define _CPH_CUPS_IS_VALID(name, name_for_str) \ +static gboolean \ +_cph_cups_is_##name##_valid (CphCups *cups, \ + const char *str) \ +{ \ + char *error; \ + \ + if (_cph_cups_is_string_printable (str)) \ + return TRUE; \ + \ + error = g_strdup_printf ("\"%s\" is not a valid %s.", \ + str, name_for_str); \ + _cph_cups_set_internal_status (cups, error); \ + g_free (error); \ + \ + return FALSE; \ +} + static gboolean _cph_cups_is_printer_name_valid_internal (const char *name) { @@ -260,21 +278,7 @@ _cph_cups_is_printer_name_valid (CphCups *cups, return FALSE; } -static gboolean -_cph_cups_is_printer_uri_valid (CphCups *cups, - const char *uri) -{ - char *error; - - if (_cph_cups_is_string_printable (uri)) - return TRUE; - - error = g_strdup_printf ("\"%s\" is not a valid printer URI.", uri); - _cph_cups_set_internal_status (cups, error); - g_free (error); - - return FALSE; -} +_CPH_CUPS_IS_VALID (printer_uri, "printer URI") /****************************************************** * Helpers -- cgit v1.2.3