1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1998-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *               Glenn Fowler <glenn.s.fowler@gmail.com>                *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 
22 /*
23  * initialize a pzip discipline library
24  */
25 
26 #include "pzlib.h"
27 
28 const char*
pzinit(register Pz_t * pz,register const char * name,Pzinit_f initf)29 pzinit(register Pz_t* pz, register const char* name, Pzinit_f initf)
30 {
31 	const char*		options;
32 	const char*		usage;
33 	char*			id;
34 
35 	options = pz->disc->options;
36 	if (!(usage = (*initf)(pz, pz->disc)))
37 	{
38 		if (pz->disc && pz->disc->errorf)
39 		{
40 			if (id = strchr((char*)state.id, ':'))
41 				id++;
42 			else
43 				id = (char*)state.id;
44 			(*pz->disc->errorf)(pz, pz->disc, 2, "%s: %s_init: initialization function error", name, id);
45 		}
46 		return 0;
47 	}
48 	optget(NiL, usage);
49 	if (pz->disc->options != options)
50 	{
51 		if (!pz->disc->options)
52 			pz->options = 0;
53 		else if (!(pz->options = vmstrdup(pz->vm, pz->disc->options)))
54 		{
55 			pznospace(pz);
56 			return 0;
57 		}
58 	}
59 	if (pz->options && pzoptions(pz, pz->part, pz->options, 0) < 0)
60 		return 0;
61 	return usage;
62 }
63