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