flist/flist32_from_str.c

Go to the documentation of this file.
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 "strtok.h"
00019 
00020 int flist32_from_str(const char *str, const flist32_t list[],
00021                 uint32_t *flags, uint32_t *mask,
00022                 char clmod, char *delim)
00023 {
00024         char *token;
00025         int clear = 0;
00026         uint32_t cur_flag;
00027 
00028         strtok_t _st, *st = &_st, *p;
00029 
00030         if (!strtok_init_str(st, str, delim, 0))
00031                 return -1;
00032 
00033         strtok_for_each(st, p) {
00034                 token = p->token;
00035 
00036                 if (*token == clmod)
00037                         clear = 1;
00038 
00039                 cur_flag = flist32_getval(list, token+clear);
00040 
00041                 if (!cur_flag) {
00042                         strtok_free(st);
00043                         return -1;
00044                 }
00045 
00046                 if (clear) {
00047                         *flags &= ~cur_flag;
00048                         *mask  |=  cur_flag;
00049                 } else {
00050                         *flags |=  cur_flag;
00051                         *mask  |=  cur_flag;
00052                 }
00053         }
00054 
00055         strtok_free(st);
00056 
00057         return 0;
00058 }

Generated on Tue Jun 19 20:38:26 2007 for lucid by  doxygen 1.5.2