00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00016 00017 #include "flist.h" 00018 #include "str.h" 00019 #include "stralloc.h" 00020 00021 char *flist32_to_str(const flist32_t list[], uint32_t val, char *delim) 00022 { 00023 int i; 00024 char *buf; 00025 stralloc_t _sa, *sa = &_sa; 00026 00027 stralloc_init(sa); 00028 00029 for (i = 0; list[i].key; i++) 00030 if (val & list[i].val) 00031 stralloc_catf(sa, "%s%s", list[i].key, delim); 00032 00033 if (sa->len > 0) 00034 sa->len -= str_len(delim); 00035 00036 buf = stralloc_finalize(sa); 00037 00038 stralloc_free(sa); 00039 return buf; 00040 }