lib.h revision 7999
1/* $Id: lib.h,v 1.14 1995/04/22 07:41:01 jkh 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);
112long		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		isempty(char *);
126char		*get_file_contents(char *);
127void		write_file(char *, char *);
128void		copy_file(char *, char *, char *);
129void		move_file(char *, char *, char *);
130void		copy_hierarchy(char *, char *, Boolean);
131int		delete_hierarchy(char *, Boolean, Boolean);
132int		unpack(char *, char *);
133void		format_cmd(char *, char *, char *, char *);
134
135/* Msg */
136void		upchuck(const char *);
137void		barf(const char *, ...);
138void		whinge(const char *, ...);
139Boolean		y_or_n(Boolean, const char *, ...);
140
141/* Packing list */
142PackingList	new_plist_entry(void);
143PackingList	last_plist(Package *);
144PackingList	find_plist(Package *, plist_t);
145char		*find_plist_option(Package *, char *name);
146void		plist_delete(Package *, Boolean, plist_t, char *);
147void		free_plist(Package *);
148void		mark_plist(Package *);
149void		csum_plist_entry(char *, PackingList);
150void		add_plist(Package *, plist_t, char *);
151void		add_plist_top(Package *, plist_t, char *);
152void		write_plist(Package *, FILE *);
153void		read_plist(Package *, FILE *);
154int		plist_cmd(char *, char **);
155int		delete_package(Boolean, Boolean, Package *);
156
157/* For all */
158void		usage(const char *, const char *, ...);
159int		pkg_perform(char **);
160
161/* Externs */
162extern Boolean	Verbose;
163extern Boolean	Fake;
164extern int	AutoAnswer;
165
166#endif /* _INST_LIB_LIB_H_ */
167