chiark / gitweb /
Add gettext support
[elogind.git] / src / shared / util.h
index 7dfabbc07d7701802790921e690fb805b83e0e25..45cb09443d62edd896c2c106e4ba6280f9b2ecf9 100644 (file)
@@ -355,16 +355,11 @@ static inline uint32_t random_u32(void) {
                 return name##_table[i];                                 \
         }
 
-#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope)        \
-        scope type name##_from_string(const char *s) {                  \
-                type i;                                                 \
-                if (!s)                                                 \
-                        return (type) -1;                               \
-                for (i = 0; i < (type)ELEMENTSOF(name##_table); i++)    \
-                        if (name##_table[i] &&                          \
-                            streq(name##_table[i], s))                  \
-                                return i;                               \
-                return (type) -1;                                       \
+ssize_t string_table_lookup(const char * const *table, size_t len, const char *key);
+
+#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope)                                \
+        scope inline type name##_from_string(const char *s) {                                   \
+                return (type)string_table_lookup(name##_table, ELEMENTSOF(name##_table), s);    \
         }
 
 #define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope)                    \
@@ -742,6 +737,8 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
                  int (*compar) (const void *, const void *, void *),
                  void *arg);
 
+#define _(String) gettext (String)
+void init_gettext(void);
 bool is_locale_utf8(void);
 
 typedef enum DrawSpecialChar {
@@ -872,16 +869,6 @@ static inline unsigned log2u(unsigned x) {
         return sizeof(unsigned) * 8 - __builtin_clz(x) - 1;
 }
 
-static inline unsigned log2u64(uint64_t x) {
-        assert(x > 0);
-
-#if __SIZEOF_LONG_LONG__ == 8
-        return 64 - __builtin_clzll(x) - 1;
-#else
-#error "Wut?"
-#endif
-}
-
 static inline unsigned log2u_round_up(unsigned x) {
         assert(x > 0);