lib.h revision 16549
1/* $Id: lib.h,v 1.20 1996/06/08 00:46:32 alex Exp $ */
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 <stdio.h>
28#include <stdlib.h>
29#include <stdarg.h>
30#include <string.h>
31#include <unistd.h>
32#include <ctype.h>
33#include <dirent.h>
34#include <sys/stat.h>
35#include <sys/types.h>
36#include <sys/file.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 DEINSTALL_FNAME	"+DEINSTALL"
70#define REQUIRE_FNAME	"+REQUIRE"
71#define REQUIRED_BY_FNAME	"+REQUIRED_BY"
72#define DISPLAY_FNAME	"+DISPLAY"
73#define MTREE_FNAME	"+MTREE_DIRS"
74
75#define CMD_CHAR	'@'	/* prefix for extended PLIST cmd */
76
77/* The name of the "prefix" environment variable given to scripts */
78#define PKG_PREFIX_VNAME	"PKG_PREFIX"
79
80enum _plist_t {
81    PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
82    PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT,
83    PLIST_IGNORE, PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
84    PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST,
85    PLIST_OPTION
86};
87typedef enum _plist_t plist_t;
88
89/* Types */
90typedef unsigned int Boolean;
91
92struct _plist {
93    struct _plist *prev, *next;
94    char *name;
95    Boolean marked;
96    plist_t type;
97};
98typedef struct _plist *PackingList;
99
100struct _pack {
101    struct _plist *head, *tail;
102};
103typedef struct _pack Package;
104
105/* Prototypes */
106/* Misc */
107int		vsystem(const char *, ...);
108void		cleanup(int);
109char		*make_playpen(char *, size_t);
110char		*where_playpen(void);
111void		leave_playpen(char *);
112off_t		min_free(char *);
113
114/* String */
115char 		*get_dash_string(char **);
116char		*copy_string(char *);
117Boolean		suffix(char *, char *);
118void		nuke_suffix(char *);
119void		str_lowercase(char *);
120char		*basename_of(char *);
121char		*strconcat(char *, char *);
122
123/* File */
124Boolean		fexists(char *);
125Boolean		isdir(char *);
126Boolean		isemptydir(char *fname);
127Boolean		isemptyfile(char *fname);
128Boolean         isfile(char *);
129Boolean		isempty(char *);
130Boolean		isURL(char *);
131char		*fileGetURL(char *, char *);
132char		*fileURLFilename(char *, char *, int);
133char		*fileURLHost(char *, char *, int);
134char		*fileFindByPath(char *, char *);
135char		*fileGetContents(char *);
136void		write_file(char *, char *);
137void		copy_file(char *, char *, char *);
138void		move_file(char *, char *, char *);
139void		copy_hierarchy(char *, char *, Boolean);
140int		delete_hierarchy(char *, Boolean, Boolean);
141int		unpack(char *, char *);
142void		format_cmd(char *, char *, char *, char *);
143
144/* Msg */
145void		upchuck(const char *);
146void		barf(const char *, ...);
147void		whinge(const char *, ...);
148Boolean		y_or_n(Boolean, const char *, ...);
149
150/* Packing list */
151PackingList	new_plist_entry(void);
152PackingList	last_plist(Package *);
153PackingList	find_plist(Package *, plist_t);
154char		*find_plist_option(Package *, char *name);
155void		plist_delete(Package *, Boolean, plist_t, char *);
156void		free_plist(Package *);
157void		mark_plist(Package *);
158void		csum_plist_entry(char *, PackingList);
159void		add_plist(Package *, plist_t, char *);
160void		add_plist_top(Package *, plist_t, char *);
161void		delete_plist(Package *pkg, Boolean all, plist_t type, char *name);
162void		write_plist(Package *, FILE *);
163void		read_plist(Package *, FILE *);
164int		plist_cmd(char *, char **);
165int		delete_package(Boolean, Boolean, Package *);
166
167/* For all */
168void		usage(const char *, const char *, ...);
169int		pkg_perform(char **);
170
171/* Externs */
172extern Boolean	Verbose;
173extern Boolean	Fake;
174extern int	AutoAnswer;
175
176#endif /* _INST_LIB_LIB_H_ */
177