Merge from vendor branch GCC:
[dragonfly.git] / usr.sbin / pkg_install / lib / lib.h
1 /*
2  * FreeBSD install - a package for the installation and maintainance
3  * of non-core utilities.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * Jordan K. Hubbard
15  * 18 July 1993
16  *
17  * Include and define various things wanted by the library routines.
18  *
19  * $FreeBSD: src/usr.sbin/pkg_install/lib/lib.h,v 1.55 2005/01/04 16:18:55 paul Exp $
20  * $DragonFly: src/usr.sbin/pkg_install/lib/Attic/lib.h,v 1.5 2005/03/08 19:11:30 joerg Exp $
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 >= 600000
81 #define INDEX_FNAME             "INDEX-6"
82 #elif defined(__FreeBSD_version) && __FreeBSD_version >= 500036
83 #define INDEX_FNAME             "INDEX-5"
84 #else
85 #define INDEX_FNAME             "INDEX"
86 #endif
87
88 #define CMD_CHAR                '@'     /* prefix for extended PLIST cmd */
89
90 /* The name of the "prefix" environment variable given to scripts */
91 #define PKG_PREFIX_VNAME        "PKG_PREFIX"
92
93 /*
94  * Version of the package tools - increase only when some
95  * functionality used by bsd.port.mk is changed, added or removed
96  */
97 #define PKG_INSTALL_VERSION     20040629
98
99 #define PKG_WRAPCONF_FNAME      "/var/db/pkg_install.conf"
100 #define main(argc, argv)        real_main(argc, argv)
101
102 /* Version numbers to assist with changes in package file format */
103 #define PLIST_FMT_VER_MAJOR     1
104 #define PLIST_FMT_VER_MINOR     1
105
106 enum _plist_t {
107     PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
108     PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
109     PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
110     PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM, 
111     PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN
112 };
113 typedef enum _plist_t plist_t;
114
115 enum _match_t {
116     MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX
117 };
118 typedef enum _match_t match_t;
119
120 /* Types */
121 typedef unsigned int Boolean;
122
123 struct _plist {
124     struct _plist *prev, *next;
125     char *name;
126     Boolean marked;
127     plist_t type;
128 };
129 typedef struct _plist *PackingList;
130
131 struct _pack {
132     struct _plist *head, *tail;
133     const char *name;
134     const char *origin;
135     int fmtver_maj, fmtver_mnr;
136 };
137 typedef struct _pack Package;
138
139 struct reqr_by_entry {
140     STAILQ_ENTRY(reqr_by_entry) link;
141     char pkgname[PATH_MAX];
142 };
143 STAILQ_HEAD(reqr_by_head, reqr_by_entry);
144                 
145 /* Prototypes */
146 /* Misc */
147 int             vsystem(const char *, ...);
148 char            *vpipe(const char *, ...);
149 void            cleanup(int);
150 char            *make_playpen(char *, off_t);
151 char            *where_playpen(void);
152 void            leave_playpen(void);
153 off_t           min_free(const char *);
154
155 /* String */
156 char            *get_dash_string(char **);
157 char            *copy_string(const char *);
158 char            *copy_string_adds_newline(const char *);
159 Boolean         suffix(const char *, const char *);
160 void            nuke_suffix(char *);
161 void            str_lowercase(char *);
162 char            *strconcat(const char *, const char *);
163 char            *get_string(char *, int, FILE *);
164
165 /* File */
166 Boolean         fexists(const char *);
167 Boolean         isdir(const char *);
168 Boolean         isemptydir(const char *fname);
169 Boolean         isemptyfile(const char *fname);
170 Boolean         isfile(const char *);
171 Boolean         isempty(const char *);
172 Boolean         issymlink(const char *);
173 Boolean         isURL(const char *);
174 char            *fileGetURL(const char *, const char *);
175 char            *fileFindByPath(const char *, const char *);
176 char            *fileGetContents(const char *);
177 void            write_file(const char *, const char *);
178 void            copy_file(const char *, const char *, const char *);
179 void            move_file(const char *, const char *, const char *);
180 void            copy_hierarchy(const char *, const char *, Boolean);
181 int             delete_hierarchy(const char *, Boolean, Boolean);
182 int             unpack(const char *, const char *);
183 void            format_cmd(char *, int, const char *, const char *, const char *);
184
185 /* Msg */
186 void            upchuck(const char *);
187 void            barf(const char *, ...);
188 void            whinge(const char *, ...);
189 Boolean         y_or_n(Boolean, const char *, ...);
190
191 /* Packing list */
192 PackingList     new_plist_entry(void);
193 PackingList     last_plist(Package *);
194 PackingList     find_plist(Package *, plist_t);
195 char            *find_plist_option(Package *, const char *name);
196 void            plist_delete(Package *, Boolean, plist_t, const char *);
197 void            free_plist(Package *);
198 void            mark_plist(Package *);
199 void            csum_plist_entry(char *, PackingList);
200 void            add_plist(Package *, plist_t, const char *);
201 void            add_plist_top(Package *, plist_t, const char *);
202 void            delete_plist(Package *pkg, Boolean all, plist_t type, const char *name);
203 void            write_plist(Package *, FILE *);
204 void            read_plist(Package *, FILE *);
205 int             plist_cmd(const char *, char **);
206 int             delete_package(Boolean, Boolean, Package *);
207 Boolean         make_preserve_name(char *, int, const char *, const char *);
208
209 /* For all */
210 int             pkg_perform(char **);
211 int             real_main(int, char **);
212
213 /* Query installed packages */
214 char            **matchinstalled(match_t, char **, int *);
215 char            **matchbyorigin(const char *, int *);
216 int             isinstalledpkg(const char *name);
217 int             pattern_match(match_t MatchType, char *pattern, const char *pkgname);
218
219 /* Dependencies */
220 int             sortdeps(char **);
221 int             chkifdepends(const char *, const char *);
222 int             requiredby(const char *, struct reqr_by_head **, Boolean, Boolean);
223
224 /* Version */
225 int             verscmp(Package *, int, int);
226 int             version_cmp(const char *, const char *);
227
228 /* Externs */
229 extern Boolean  Quiet;
230 extern Boolean  Verbose;
231 extern Boolean  Fake;
232 extern Boolean  Force;
233 extern int      AutoAnswer;
234
235 #endif /* _INST_LIB_LIB_H_ */