lib.h revision 74295
1/* $FreeBSD: head/usr.sbin/pkg_install/lib/lib.h 74295 2001-03-15 10:47:00Z sobomax $ */
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
64/* The names of our "special" files */
65#define CONTENTS_FNAME		"+CONTENTS"
66#define COMMENT_FNAME		"+COMMENT"
67#define DESC_FNAME		"+DESC"
68#define INSTALL_FNAME		"+INSTALL"
69#define POST_INSTALL_FNAME	"+POST-INSTALL"
70#define DEINSTALL_FNAME		"+DEINSTALL"
71#define POST_DEINSTALL_FNAME	"+POST-DEINSTALL"
72#define REQUIRE_FNAME		"+REQUIRE"
73#define REQUIRED_BY_FNAME	"+REQUIRED_BY"
74#define DISPLAY_FNAME		"+DISPLAY"
75#define MTREE_FNAME		"+MTREE_DIRS"
76
77#define CMD_CHAR		'@'	/* prefix for extended PLIST cmd */
78
79/* The name of the "prefix" environment variable given to scripts */
80#define PKG_PREFIX_VNAME	"PKG_PREFIX"
81
82enum _plist_t {
83    PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
84    PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
85    PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
86    PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST,
87    PLIST_OPTION
88};
89typedef enum _plist_t plist_t;
90
91enum _match_t {
92    MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_REGEX
93};
94typedef enum _match_t match_t;
95
96/* Types */
97typedef unsigned int Boolean;
98
99struct _plist {
100    struct _plist *prev, *next;
101    char *name;
102    Boolean marked;
103    plist_t type;
104};
105typedef struct _plist *PackingList;
106
107struct _pack {
108    struct _plist *head, *tail;
109};
110typedef struct _pack Package;
111
112/* Prototypes */
113/* Misc */
114int		vsystem(const char *, ...);
115void		cleanup(int);
116char		*make_playpen(char *, size_t);
117char		*where_playpen(void);
118void		leave_playpen(void);
119off_t		min_free(char *);
120
121/* String */
122char 		*get_dash_string(char **);
123char		*copy_string(char *);
124Boolean		suffix(char *, char *);
125void		nuke_suffix(char *);
126void		str_lowercase(char *);
127char		*basename_of(char *);
128char		*strconcat(char *, char *);
129
130/* File */
131Boolean		fexists(char *);
132Boolean		isdir(char *);
133Boolean		isemptydir(char *fname);
134Boolean		isemptyfile(char *fname);
135Boolean         isfile(char *);
136Boolean		isempty(char *);
137Boolean		issymlink(char *);
138Boolean		isURL(char *);
139char		*fileGetURL(char *, char *);
140char		*fileFindByPath(char *, char *);
141char		*fileGetContents(char *);
142void		write_file(char *, char *);
143void		copy_file(char *, char *, char *);
144void		move_file(char *, char *, char *);
145void		copy_hierarchy(char *, char *, Boolean);
146int		delete_hierarchy(char *, Boolean, Boolean);
147int		unpack(char *, char *);
148void		format_cmd(char *, char *, char *, char *);
149
150/* Msg */
151void		upchuck(const char *);
152void		barf(const char *, ...);
153void		whinge(const char *, ...);
154Boolean		y_or_n(Boolean, const char *, ...);
155
156/* Packing list */
157PackingList	new_plist_entry(void);
158PackingList	last_plist(Package *);
159PackingList	find_plist(Package *, plist_t);
160char		*find_plist_option(Package *, char *name);
161void		plist_delete(Package *, Boolean, plist_t, char *);
162void		free_plist(Package *);
163void		mark_plist(Package *);
164void		csum_plist_entry(char *, PackingList);
165void		add_plist(Package *, plist_t, char *);
166void		add_plist_top(Package *, plist_t, char *);
167void		delete_plist(Package *pkg, Boolean all, plist_t type, char *name);
168void		write_plist(Package *, FILE *);
169void		read_plist(Package *, FILE *);
170int		plist_cmd(char *, char **);
171int		delete_package(Boolean, Boolean, Package *);
172Boolean 	make_preserve_name(char *, int, char *, char *);
173
174/* For all */
175int		pkg_perform(char **);
176
177/* Query installed packages */
178char		**matchinstalled(match_t, char **, int *);
179
180/* Dependencies */
181int		sortdeps(char **);
182int		chkifdepends(char *, char *);
183
184/* Externs */
185extern Boolean	Verbose;
186extern Boolean	Fake;
187extern Boolean  Force;
188extern int	AutoAnswer;
189
190#endif /* _INST_LIB_LIB_H_ */
191