Commit 60c1afe7 60c1afe7697f18c7b0ed6d3adc65334673e4531c by Sergey Poznyakoff

(mutil_parse_field_map): New function

1 parent edbc0d19
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2004, 2005, 2 Copyright (C) 1999, 2000, 2001, 2004, 2005,
3 2006 Free Software Foundation, Inc. 3 2006, 2007 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -148,6 +148,9 @@ extern int mu_mh_delim (const char *str); ...@@ -148,6 +148,9 @@ extern int mu_mh_delim (const char *str);
148 extern size_t mu_strftime (char *s, size_t max, const char *format, 148 extern size_t mu_strftime (char *s, size_t max, const char *format,
149 const struct tm *tm); 149 const struct tm *tm);
150 150
151
152 extern int mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab,
153 int *perr);
151 154
152 #ifdef __cplusplus 155 #ifdef __cplusplus
153 } 156 }
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2 Copyright (C) 1999, 2000, 2001, 2002, 2003,
3 2005, 2006 Free Software Foundation, Inc. 3 2005, 2006, 2007 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
43 #endif 43 #endif
44 44
45 #include <mailutils/address.h> 45 #include <mailutils/address.h>
46 #include <mailutils/assoc.h>
47 #include <mailutils/argcv.h>
46 #include <mailutils/error.h> 48 #include <mailutils/error.h>
47 #include <mailutils/errno.h> 49 #include <mailutils/errno.h>
48 #include <mailutils/iterator.h> 50 #include <mailutils/iterator.h>
...@@ -1402,4 +1404,57 @@ mu_strftime (char *s, size_t max, const char *format, const struct tm *tm) ...@@ -1402,4 +1404,57 @@ mu_strftime (char *s, size_t max, const char *format, const struct tm *tm)
1402 return size; 1404 return size;
1403 } 1405 }
1404 1406
1405 1407
1408 static void
1409 assoc_str_free (void *data)
1410 {
1411 free (data);
1412 }
1413
1414 int
1415 mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr)
1416 {
1417 int rc;
1418 int i;
1419 char *copy = strdup (map);
1420 char *sp, *tok;
1421 mu_assoc_t assoc_tab = NULL;
1422
1423 for (tok = strtok_r (copy, ",", &sp); tok; tok = strtok_r (NULL, ",", &sp))
1424 {
1425 char *p = strchr (tok, '=');
1426 char *pptr;
1427
1428 if (!p)
1429 {
1430 rc = EINVAL;
1431 break;
1432 }
1433 if (!assoc_tab)
1434 {
1435 rc = mu_assoc_create (&assoc_tab, sizeof(char*));
1436 if (rc)
1437 break;
1438 mu_assoc_set_free (assoc_tab, assoc_str_free);
1439 *passoc_tab = assoc_tab;
1440 }
1441 *p++ = 0;
1442 pptr = strdup (p);
1443 if (!pptr)
1444 {
1445 rc = errno;
1446 break;
1447 }
1448 rc = mu_assoc_install (assoc_tab, tok, &pptr);
1449 if (rc)
1450 {
1451 free (p);
1452 break;
1453 }
1454 }
1455
1456 free (copy);
1457 if (rc && perr)
1458 *perr = i;
1459 return rc;
1460 }
......