]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/pkg_install/lib/lib.h
This commit was generated by cvs2svn to compensate for changes in r172771,
[FreeBSD/FreeBSD.git] / usr.sbin / pkg_install / lib / lib.h
1 /* $FreeBSD$ */
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 <sys/queue.h>
31 #include <ctype.h>
32 #include <dirent.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <unistd.h>
38
39 /* Macros */
40 #define SUCCESS (0)
41 #define FAIL    (-1)
42
43 #ifndef TRUE
44 #define TRUE    (1)
45 #endif
46
47 #ifndef FALSE
48 #define FALSE   (0)
49 #endif
50
51 #define YES             2
52 #define NO              1
53
54 /* Usually "rm", but often "echo" during debugging! */
55 #define REMOVE_CMD      "/bin/rm"
56
57 /* Usually "rm", but often "echo" during debugging! */
58 #define RMDIR_CMD       "/bin/rmdir"
59
60 /* Where we put logging information by default, else ${PKG_DBDIR} if set */
61 #define DEF_LOG_DIR     "/var/db/pkg"
62 /* just in case we change the environment variable name */
63 #define PKG_DBDIR       "PKG_DBDIR"
64 /* macro to get name of directory where we put logging information */
65 #define LOG_DIR         (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR)
66
67 /* The names of our "special" files */
68 #define CONTENTS_FNAME          "+CONTENTS"
69 #define COMMENT_FNAME           "+COMMENT"
70 #define DESC_FNAME              "+DESC"
71 #define INSTALL_FNAME           "+INSTALL"
72 #define POST_INSTALL_FNAME      "+POST-INSTALL"
73 #define DEINSTALL_FNAME         "+DEINSTALL"
74 #define POST_DEINSTALL_FNAME    "+POST-DEINSTALL"
75 #define REQUIRE_FNAME           "+REQUIRE"
76 #define REQUIRED_BY_FNAME       "+REQUIRED_BY"
77 #define DISPLAY_FNAME           "+DISPLAY"
78 #define MTREE_FNAME             "+MTREE_DIRS"
79
80 #if defined(__FreeBSD_version) && __FreeBSD_version >= 800000
81 #define INDEX_FNAME             "INDEX-8"
82 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000
83 #define INDEX_FNAME             "INDEX-7"
84 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
85 #define INDEX_FNAME             "INDEX-6"
86 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 500036
87 #define INDEX_FNAME             "INDEX-5"
88 #else
89 #define INDEX_FNAME             "INDEX"
90 #endif
91
92 #define CMD_CHAR                '@'     /* prefix for extended PLIST cmd */
93
94 /* The name of the "prefix" environment variable given to scripts */
95 #define PKG_PREFIX_VNAME        "PKG_PREFIX"
96
97 /*
98  * Version of the package tools - increase only when some
99  * functionality used by bsd.port.mk is changed, added or removed
100  */
101 #define PKG_INSTALL_VERSION     20040629
102
103 #define PKG_WRAPCONF_FNAME      "/var/db/pkg_install.conf"
104 #define main(argc, argv)        real_main(argc, argv)
105
106 /* Version numbers to assist with changes in package file format */
107 #define PLIST_FMT_VER_MAJOR     1
108 #define PLIST_FMT_VER_MINOR     1
109
110 enum _plist_t {
111     PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
112     PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
113     PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
114     PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM,
115     PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN,
116     PLIST_NOINST
117 };
118 typedef enum _plist_t plist_t;
119
120 enum _match_t {
121     MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX
122 };
123 typedef enum _match_t match_t;
124
125 /* Types */
126 typedef unsigned int Boolean;
127
128 struct _plist {
129     struct _plist *prev, *next;
130     char *name;
131     Boolean marked;
132     plist_t type;
133 };
134 typedef struct _plist *PackingList;
135
136 struct _pack {
137     struct _plist *head, *tail;
138     const char *name;
139     const char *origin;
140     int fmtver_maj, fmtver_mnr;
141 };
142 typedef struct _pack Package;
143
144 struct reqr_by_entry {
145     STAILQ_ENTRY(reqr_by_entry) link;
146     char pkgname[PATH_MAX];
147 };
148 STAILQ_HEAD(reqr_by_head, reqr_by_entry);
149
150 /* Prototypes */
151 /* Misc */
152 int             vsystem(const char *, ...);
153 char            *vpipe(const char *, ...);
154 void            cleanup(int);
155 char            *make_playpen(char *, off_t);
156 char            *where_playpen(void);
157 void            leave_playpen(void);
158 off_t           min_free(const char *);
159
160 /* String */
161 char            *get_dash_string(char **);
162 char            *copy_string(const char *);
163 char            *copy_string_adds_newline(const char *);
164 Boolean         suffix(const char *, const char *);
165 void            nuke_suffix(char *);
166 void            str_lowercase(char *);
167 char            *strconcat(const char *, const char *);
168 char            *get_string(char *, int, FILE *);
169
170 /* File */
171 Boolean         fexists(const char *);
172 Boolean         isdir(const char *);
173 Boolean         isemptydir(const char *fname);
174 Boolean         isemptyfile(const char *fname);
175 Boolean         isfile(const char *);
176 Boolean         isempty(const char *);
177 Boolean         issymlink(const char *);
178 Boolean         isURL(const char *);
179 char            *fileGetURL(const char *, const char *, int);
180 char            *fileFindByPath(const char *, const char *);
181 char            *fileGetContents(const char *);
182 void            write_file(const char *, const char *);
183 void            copy_file(const char *, const char *, const char *);
184 void            move_file(const char *, const char *, const char *);
185 void            copy_hierarchy(const char *, const char *, Boolean);
186 int             delete_hierarchy(const char *, Boolean, Boolean);
187 int             unpack(const char *, const char *);
188 void            format_cmd(char *, int, const char *, const char *, const char *);
189
190 /* Msg */
191 void            upchuck(const char *);
192 void            barf(const char *, ...);
193 void            whinge(const char *, ...);
194 Boolean         y_or_n(Boolean, const char *, ...);
195
196 /* Packing list */
197 PackingList     new_plist_entry(void);
198 PackingList     last_plist(Package *);
199 PackingList     find_plist(Package *, plist_t);
200 char            *find_plist_option(Package *, const char *name);
201 void            plist_delete(Package *, Boolean, plist_t, const char *);
202 void            free_plist(Package *);
203 void            mark_plist(Package *);
204 void            csum_plist_entry(char *, PackingList);
205 void            add_plist(Package *, plist_t, const char *);
206 void            add_plist_top(Package *, plist_t, const char *);
207 void            delete_plist(Package *pkg, Boolean all, plist_t type, const char *name);
208 void            write_plist(Package *, FILE *);
209 void            read_plist(Package *, FILE *);
210 int             plist_cmd(const char *, char **);
211 int             delete_package(Boolean, Boolean, Package *);
212 Boolean         make_preserve_name(char *, int, const char *, const char *);
213
214 /* For all */
215 int             pkg_perform(char **);
216 int             real_main(int, char **);
217
218 /* Query installed packages */
219 char            **matchinstalled(match_t, char **, int *);
220 char            **matchbyorigin(const char *, int *);
221 int             isinstalledpkg(const char *name);
222 int             pattern_match(match_t MatchType, char *pattern, const char *pkgname);
223
224 /* Dependencies */
225 int             sortdeps(char **);
226 int             chkifdepends(const char *, const char *);
227 int             requiredby(const char *, struct reqr_by_head **, Boolean, Boolean);
228
229 /* Version */
230 int             verscmp(Package *, int, int);
231 int             version_cmp(const char *, const char *);
232
233 /* Externs */
234 extern Boolean  Quiet;
235 extern Boolean  Fake;
236 extern Boolean  Force;
237 extern int      AutoAnswer;
238 extern int      Verbose;
239
240 #endif /* _INST_LIB_LIB_H_ */