1228753Smm/*-
2228753Smm * Copyright (c) 2003-2007 Tim Kientzle
3228753Smm * All rights reserved.
4228753Smm *
5228753Smm * Redistribution and use in source and binary forms, with or without
6228753Smm * modification, are permitted provided that the following conditions
7228753Smm * are met:
8228753Smm * 1. Redistributions of source code must retain the above copyright
9228753Smm *    notice, this list of conditions and the following disclaimer.
10228753Smm * 2. Redistributions in binary form must reproduce the above copyright
11228753Smm *    notice, this list of conditions and the following disclaimer in the
12228753Smm *    documentation and/or other materials provided with the distribution.
13228753Smm *
14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24228753Smm */
25228753Smm
26228753Smm#include "archive_platform.h"
27229592Smm__FBSDID("$FreeBSD$");
28228753Smm
29228753Smm#ifdef HAVE_SYS_TYPES_H
30228753Smm#include <sys/types.h>
31228753Smm#endif
32228753Smm
33228753Smm#ifdef HAVE_ERRNO_H
34228753Smm#include <errno.h>
35228753Smm#endif
36228753Smm#ifdef HAVE_STRING_H
37228753Smm#include <string.h>
38228753Smm#endif
39228753Smm
40228753Smm#include "archive.h"
41228753Smm#include "archive_private.h"
42228753Smm
43228753Smm/* A table that maps names to functions. */
44228753Smmstatic
45228753Smmstruct { const char *name; int (*setter)(struct archive *); } names[] =
46228753Smm{
47228753Smm	{ "ar",		archive_write_set_format_ar_bsd },
48228753Smm	{ "arbsd",	archive_write_set_format_ar_bsd },
49228753Smm	{ "argnu",	archive_write_set_format_ar_svr4 },
50228753Smm	{ "arsvr4",	archive_write_set_format_ar_svr4 },
51228753Smm	{ "cpio",	archive_write_set_format_cpio },
52228753Smm	{ "mtree",	archive_write_set_format_mtree },
53228753Smm	{ "newc",	archive_write_set_format_cpio_newc },
54228753Smm	{ "odc",	archive_write_set_format_cpio },
55228753Smm	{ "pax",	archive_write_set_format_pax },
56228753Smm	{ "posix",	archive_write_set_format_pax },
57228753Smm	{ "shar",	archive_write_set_format_shar },
58228753Smm	{ "shardump",	archive_write_set_format_shar_dump },
59228753Smm	{ "ustar",	archive_write_set_format_ustar },
60228753Smm	{ "zip",	archive_write_set_format_zip },
61228753Smm	{ NULL,		NULL }
62228753Smm};
63228753Smm
64228753Smmint
65228753Smmarchive_write_set_format_by_name(struct archive *a, const char *name)
66228753Smm{
67228753Smm	int i;
68228753Smm
69228753Smm	for (i = 0; names[i].name != NULL; i++) {
70228753Smm		if (strcmp(name, names[i].name) == 0)
71228753Smm			return ((names[i].setter)(a));
72228753Smm	}
73228753Smm
74228753Smm	archive_set_error(a, EINVAL, "No such format '%s'", name);
75228753Smm	return (ARCHIVE_FATAL);
76228753Smm}
77