1 /*
2  * shmem.c
3  *
4  * liba2ps shared memory (data used by several modules)
5  *
6  * Copyright (c) 1988, 89, 90, 91, 92, 93 Miguel Santana
7  * Copyright (c) 1995, 96, 97, 98 Akim Demaille, Miguel Santana
8  */
9 
10 /*
11  * This file is part of a2ps.
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; see the file COPYING.  If not, write to
25  * the Free Software Foundation, 59 Temple Place - Suite 330,
26  * Boston, MA 02111-1307, USA.
27  */
28 
29 /*
30  * $Id: common.c,v 1.2 1998/02/18 18:28:35 demaille Exp $
31  */
32 
33 #include "common.h"
34 #include "pathwalk.h"
35 
36 /*
37  * Default a shared mem values
38  */
39 void
a2ps_common_reset(struct a2ps_common_s * common)40 a2ps_common_reset (struct a2ps_common_s * common)
41 {
42   common->path = NULL;
43 }
44 
45 /*
46  * Create a shared mem with default values
47  */
48 struct a2ps_common_s *
a2ps_common_new(void)49 a2ps_common_new (void)
50 {
51   NEW (struct a2ps_common_s, res);
52   a2ps_common_reset (res);
53   return res;
54 }
55 
56 /*
57  * Free the common mem
58  */
59 void
a2ps_common_free(struct a2ps_common_s * common)60 a2ps_common_free (struct a2ps_common_s * common)
61 {
62   pw_free_path (common->path);
63 }
64 
65 /*
66  * Finalize the common mem to the regular values
67  * HOME is the user's home dir.
68  */
69 void
a2ps_common_finalize(struct a2ps_common_s * common,const char * home)70 a2ps_common_finalize (struct a2ps_common_s * common, const char * home)
71 {
72   char buf [512];
73 
74   /* Add the user's home .a2ps dir to the lib path unless explicitly
75    * discarded with NO_HOME_CONF */
76   if (! getenv ("NO_HOME_CONF"))
77     {
78       sprintf (buf, "%s%c.a2ps", home, DIRECTORY_SEPARATOR);
79       common->path = pw_prepend_string_to_path (common->path, buf);
80     }
81 }
82