lib.h revision 81571
1/* $FreeBSD: head/usr.sbin/pkg_install/lib/lib.h 81571 2001-08-13 04:18:30Z obrien $ */
2
3/*
4 * FreeBSD install - a package for the installation and maintainance
5 * of non-core utilities.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * Jordan K. Hubbard
17 * 18 July 1993
18 *
19 * Include and define various things wanted by the library routines.
20 *
21 */
22
23#ifndef _INST_LIB_LIB_H_
24#define _INST_LIB_LIB_H_
25
26/* Includes */
27#include <sys/param.h>
28#include <sys/file.h>
29#include <sys/stat.h>
30#include <ctype.h>
31#include <dirent.h>
32#include <stdarg.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include <unistd.h>
37
38/* Macros */
39#define SUCCESS	(0)
40#define	FAIL	(-1)
41
42#ifndef TRUE
43#define TRUE	(1)
44#endif
45
46#ifndef FALSE
47#define FALSE	(0)
48#endif
49
50#define YES		2
51#define NO		1
52
53/* Usually "rm", but often "echo" during debugging! */
54#define REMOVE_CMD	"rm"
55
56/* Usually "rm", but often "echo" during debugging! */
57#define RMDIR_CMD	"rmdir"
58
59/* Where we put logging information by default, else ${PKG_DBDIR} if set */
60#define DEF_LOG_DIR	"/var/db/pkg"
61/* just in case we change the environment variable name */
62#define PKG_DBDIR	"PKG_DBDIR"
63/* macro to get name of directory where we put logging information */
64#define LOG_DIR		(getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR)
65
66/* The names of our "special" files */
67#define CONTENTS_FNAME		"+CONTENTS"
68#define COMMENT_FNAME		"+COMMENT"
69#define DESC_FNAME		"+DESC"
70#define INSTALL_FNAME		"+INSTALL"
71#define POST_INSTALL_FNAME	"+POST-INSTALL"
72#define DEINSTALL_FNAME		"+DEINSTALL"
73#define POST_DEINSTALL_FNAME	"+POST-DEINSTALL"
74#define REQUIRE_FNAME		"+REQUIRE"
75#define REQUIRED_BY_FNAME	"+REQUIRED_BY"
76#define DISPLAY_FNAME		"+DISPLAY"
77#define MTREE_FNAME		"+MTREE_DIRS"
78
79#define CMD_CHAR		'@'	/* prefix for extended PLIST cmd */
80
81/* The name of the "prefix" environment variable given to scripts */
82#define PKG_PREFIX_VNAME	"PKG_PREFIX"
83
84enum _plist_t {
85    PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
86    PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
87    PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
88    PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST,
89    PLIST_OPTION
90};
91typedef enum _plist_t plist_t;
92
93enum _match_t {
94    MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_REGEX
95};
96typedef enum _match_t match_t;
97
98/* Types */
99typedef unsigned int Boolean;
100
101struct _plist {
102    struct _plist *prev, *next;
103    char *name;
104    Boolean marked;
105    plist_t type;
106};
107typedef struct _plist *PackingList;
108
109struct _pack {
110    struct _plist *head, *tail;
111};
112typedef struct _pack Package;
113
114/* Prototypes */
115/* Misc */
116int		vsystem(const char *, ...);
117char		*vpipe(const char *, ...);
118void		cleanup(int);
119char		*make_playpen(char *, size_t);
120char		*where_playpen(void);
121void		leave_playpen(void);
122off_t		min_free(char *);
123
124/* String */
125char 		*get_dash_string(char **);
126char		*copy_string(char *);
127Boolean		suffix(char *, char *);
128void		nuke_suffix(char *);
129void		str_lowercase(char *);
130char		*strconcat(char *, char *);
131char		*get_string(char *, int, FILE *);
132
133/* File */
134Boolean		fexists(char *);
135Boolean		isdir(char *);
136Boolean		isemptydir(char *fname);
137Boolean		isemptyfile(char *fname);
138Boolean         isfile(char *);
139Boolean		isempty(char *);
140Boolean		issymlink(char *);
141Boolean		isURL(char *);
142char		*fileGetURL(char *, char *);
143char		*fileFindByPath(char *, char *);
144char		*fileGetContents(char *);
145void		write_file(char *, char *);
146void		copy_file(char *, char *, char *);
147void		move_file(char *, char *, char *);
148void		copy_hierarchy(char *, char *, Boolean);
149int		delete_hierarchy(char *, Boolean, Boolean);
150int		unpack(char *, char *);
151void		format_cmd(char *, char *, char *, char *);
152
153/* Msg */
154void		upchuck(const char *);
155void		barf(const char *, ...);
156void		whinge(const char *, ...);
157Boolean		y_or_n(Boolean, const char *, ...);
158
159/* Packing list */
160PackingList	new_plist_entry(void);
161PackingList	last_plist(Package *);
162PackingList	find_plist(Package *, plist_t);
163char		*find_plist_option(Package *, char *name);
164void		plist_delete(Package *, Boolean, plist_t, char *);
165void		free_plist(Package *);
166void		mark_plist(Package *);
167void		csum_plist_entry(char *, PackingList);
168void		add_plist(Package *, plist_t, char *);
169void		add_plist_top(Package *, plist_t, char *);
170void		delete_plist(Package *pkg, Boolean all, plist_t type, char *name);
171void		write_plist(Package *, FILE *);
172void		read_plist(Package *, FILE *);
173int		plist_cmd(char *, char **);
174int		delete_package(Boolean, Boolean, Package *);
175Boolean 	make_preserve_name(char *, int, char *, char *);
176
177/* For all */
178int		pkg_perform(char **);
179
180/* Query installed packages */
181char		**matchinstalled(match_t, char **, int *);
182
183/* Dependencies */
184int		sortdeps(char **);
185int		chkifdepends(char *, char *);
186
187/* Externs */
188extern Boolean	Verbose;
189extern Boolean	Fake;
190extern Boolean  Force;
191extern int	AutoAnswer;
192
193#endif /* _INST_LIB_LIB_H_ */
194