Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.sbin / pkg_install / lib / lib.h
1 /* $FreeBSD: src/usr.sbin/pkg_install/lib/lib.h,v 1.29.2.12 2003/06/09 17:01:26 lioux Exp $ */
2 /* $DragonFly: src/usr.sbin/pkg_install/lib/Attic/lib.h,v 1.2 2003/06/17 04:29:59 dillon Exp $ */
3
4 /*
5  * FreeBSD install - a package for the installation and maintainance
6  * of non-core utilities.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * Jordan K. Hubbard
18  * 18 July 1993
19  *
20  * Include and define various things wanted by the library routines.
21  *
22  */
23
24 #ifndef _INST_LIB_LIB_H_
25 #define _INST_LIB_LIB_H_
26
27 /* Includes */
28 #include <sys/param.h>
29 #include <sys/file.h>
30 #include <sys/stat.h>
31 #include <sys/queue.h>
32 #include <ctype.h>
33 #include <dirent.h>
34 #include <stdarg.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <unistd.h>
39
40 /* Macros */
41 #define SUCCESS (0)
42 #define FAIL    (-1)
43
44 #ifndef TRUE
45 #define TRUE    (1)
46 #endif
47
48 #ifndef FALSE
49 #define FALSE   (0)
50 #endif
51
52 #define YES             2
53 #define NO              1
54
55 /* Usually "rm", but often "echo" during debugging! */
56 #define REMOVE_CMD      "rm"
57
58 /* Usually "rm", but often "echo" during debugging! */
59 #define RMDIR_CMD       "rmdir"
60
61 /* Where we put logging information by default, else ${PKG_DBDIR} if set */
62 #define DEF_LOG_DIR     "/var/db/pkg"
63 /* just in case we change the environment variable name */
64 #define PKG_DBDIR       "PKG_DBDIR"
65 /* macro to get name of directory where we put logging information */
66 #define LOG_DIR         (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR)
67
68 /* The names of our "special" files */
69 #define CONTENTS_FNAME          "+CONTENTS"
70 #define COMMENT_FNAME           "+COMMENT"
71 #define DESC_FNAME              "+DESC"
72 #define INSTALL_FNAME           "+INSTALL"
73 #define POST_INSTALL_FNAME      "+POST-INSTALL"
74 #define DEINSTALL_FNAME         "+DEINSTALL"
75 #define POST_DEINSTALL_FNAME    "+POST-DEINSTALL"
76 #define REQUIRE_FNAME           "+REQUIRE"
77 #define REQUIRED_BY_FNAME       "+REQUIRED_BY"
78 #define DISPLAY_FNAME           "+DISPLAY"
79 #define MTREE_FNAME             "+MTREE_DIRS"
80
81 #define CMD_CHAR                '@'     /* prefix for extended PLIST cmd */
82
83 /* The name of the "prefix" environment variable given to scripts */
84 #define PKG_PREFIX_VNAME        "PKG_PREFIX"
85
86 /* Version numbers to assist with changes in package file format */
87 #define PLIST_FMT_VER_MAJOR     1
88 #define PLIST_FMT_VER_MINOR     1
89
90 enum _plist_t {
91     PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
92     PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
93     PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
94     PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST,
95     PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN
96 };
97 typedef enum _plist_t plist_t;
98
99 enum _match_t {
100     MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_REGEX
101 };
102 typedef enum _match_t match_t;
103
104 /* Types */
105 typedef unsigned int Boolean;
106
107 struct _plist {
108     struct _plist *prev, *next;
109     char *name;
110     Boolean marked;
111     plist_t type;
112 };
113 typedef struct _plist *PackingList;
114
115 struct _pack {
116     struct _plist *head, *tail;
117     char *name;
118     char *origin;
119     int fmtver_maj, fmtver_mnr;
120 };
121 typedef struct _pack Package;
122
123 struct reqr_by_entry {
124     STAILQ_ENTRY(reqr_by_entry) link;
125     char pkgname[PATH_MAX];
126 };
127 STAILQ_HEAD(reqr_by_head, reqr_by_entry);
128                 
129 /* Prototypes */
130 /* Misc */
131 int             vsystem(const char *, ...);
132 char            *vpipe(const char *, ...);
133 void            cleanup(int);
134 char            *make_playpen(char *, off_t);
135 char            *where_playpen(void);
136 void            leave_playpen(void);
137 off_t           min_free(const char *);
138
139 /* String */
140 char            *get_dash_string(char **);
141 char            *copy_string(const char *);
142 char            *copy_string_plus_newline(const char *);
143 Boolean         suffix(const char *, const char *);
144 void            nuke_suffix(char *);
145 void            str_lowercase(char *);
146 char            *strconcat(const char *, const char *);
147 char            *get_string(char *, int, FILE *);
148
149 /* File */
150 Boolean         fexists(const char *);
151 Boolean         isdir(const char *);
152 Boolean         isemptydir(const char *fname);
153 Boolean         isemptyfile(const char *fname);
154 Boolean         isfile(const char *);
155 Boolean         isempty(const char *);
156 Boolean         issymlink(const char *);
157 Boolean         isURL(const char *);
158 char            *fileGetURL(const char *, const char *);
159 char            *fileFindByPath(const char *, const char *);
160 char            *fileGetContents(const char *);
161 void            write_file(const char *, const char *);
162 void            copy_file(const char *, const char *, const char *);
163 void            move_file(const char *, const char *, const char *);
164 void            copy_hierarchy(const char *, const char *, Boolean);
165 int             delete_hierarchy(const char *, Boolean, Boolean);
166 int             unpack(const char *, const char *);
167 void            format_cmd(char *, const char *, const char *, const char *);
168
169 /* Msg */
170 void            upchuck(const char *);
171 void            barf(const char *, ...);
172 void            whinge(const char *, ...);
173 Boolean         y_or_n(Boolean, const char *, ...);
174
175 /* Packing list */
176 PackingList     new_plist_entry(void);
177 PackingList     last_plist(Package *);
178 PackingList     find_plist(Package *, plist_t);
179 char            *find_plist_option(Package *, const char *name);
180 void            plist_delete(Package *, Boolean, plist_t, const char *);
181 void            free_plist(Package *);
182 void            mark_plist(Package *);
183 void            csum_plist_entry(char *, PackingList);
184 void            add_plist(Package *, plist_t, const char *);
185 void            add_plist_top(Package *, plist_t, const char *);
186 void            delete_plist(Package *pkg, Boolean all, plist_t type, const char *name);
187 void            write_plist(Package *, FILE *);
188 void            read_plist(Package *, FILE *);
189 int             plist_cmd(const char *, char **);
190 int             delete_package(Boolean, Boolean, Package *);
191 Boolean         make_preserve_name(char *, int, const char *, const char *);
192
193 /* For all */
194 int             pkg_perform(char **);
195
196 /* Query installed packages */
197 char            **matchinstalled(match_t, char **, int *);
198 char            **matchbyorigin(const char *, int *);
199 int             isinstalledpkg(const char *name);
200
201 /* Dependencies */
202 int             sortdeps(char **);
203 int             chkifdepends(const char *, const char *);
204 int             requiredby(const char *, struct reqr_by_head **, Boolean, Boolean);
205
206 /* Version */
207 int             verscmp(Package *, int, int);
208
209 /* Externs */
210 extern Boolean  Verbose;
211 extern Boolean  Fake;
212 extern Boolean  Force;
213 extern int      AutoAnswer;
214
215 #endif /* _INST_LIB_LIB_H_ */