lib.h revision 10309
1/* $Id: lib.h,v 1.17 1995/07/30 01:44:45 ache 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);
110void		leave_playpen(void);
111char		*where_playpen(void);
112size_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 *);
121
122/* File */
123Boolean		fexists(char *);
124Boolean		isdir(char *);
125Boolean         isfile(char *);
126Boolean		isempty(char *);
127Boolean		isURL(char *);
128char		*fileGetURL(char *);
129char		*fileURLFilename(char *, char *, int);
130char		*fileURLHost(char *, char *, int);
131char		*fileFindByPath(char *);
132char		*fileGetContents(char *);
133void		write_file(char *, char *);
134void		copy_file(char *, char *, char *);
135void		move_file(char *, char *, char *);
136void		copy_hierarchy(char *, char *, Boolean);
137int		delete_hierarchy(char *, Boolean, Boolean);
138int		unpack(char *, char *);
139void		format_cmd(char *, char *, char *, char *);
140
141/* Msg */
142void		upchuck(const char *);
143void		barf(const char *, ...);
144void		whinge(const char *, ...);
145Boolean		y_or_n(Boolean, const char *, ...);
146
147/* Packing list */
148PackingList	new_plist_entry(void);
149PackingList	last_plist(Package *);
150PackingList	find_plist(Package *, plist_t);
151char		*find_plist_option(Package *, char *name);
152void		plist_delete(Package *, Boolean, plist_t, char *);
153void		free_plist(Package *);
154void		mark_plist(Package *);
155void		csum_plist_entry(char *, PackingList);
156void		add_plist(Package *, plist_t, char *);
157void		add_plist_top(Package *, plist_t, char *);
158void		write_plist(Package *, FILE *);
159void		read_plist(Package *, FILE *);
160int		plist_cmd(char *, char **);
161int		delete_package(Boolean, Boolean, Package *);
162
163/* For all */
164void		usage(const char *, const char *, ...);
165int		pkg_perform(char **);
166
167/* Externs */
168extern Boolean	Verbose;
169extern Boolean	Fake;
170extern int	AutoAnswer;
171
172#endif /* _INST_LIB_LIB_H_ */
173