lib.h revision 4546
11541Srgrimes/* $Id: lib.h,v 1.10 1994/10/04 16:07:50 jkh Exp $ */
21541Srgrimes
31541Srgrimes/*
41541Srgrimes * FreeBSD install - a package for the installation and maintainance
51541Srgrimes * of non-core utilities.
61541Srgrimes *
71541Srgrimes * Redistribution and use in source and binary forms, with or without
81541Srgrimes * modification, are permitted provided that the following conditions
91541Srgrimes * are met:
101541Srgrimes * 1. Redistributions of source code must retain the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer.
121541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
131541Srgrimes *    notice, this list of conditions and the following disclaimer in the
141541Srgrimes *    documentation and/or other materials provided with the distribution.
151541Srgrimes *
161541Srgrimes * Jordan K. Hubbard
171541Srgrimes * 18 July 1993
181541Srgrimes *
191541Srgrimes * Include and define various things wanted by the library routines.
201541Srgrimes *
211541Srgrimes */
221541Srgrimes
231541Srgrimes#ifndef _INST_LIB_LIB_H_
241541Srgrimes#define _INST_LIB_LIB_H_
251541Srgrimes
261541Srgrimes/* Includes */
271541Srgrimes#include <stdio.h>
281541Srgrimes#include <stdlib.h>
291541Srgrimes#include <stdarg.h>
301541Srgrimes#include <string.h>
311541Srgrimes#include <unistd.h>
321541Srgrimes#include <ctype.h>
331541Srgrimes#include <dirent.h>
341541Srgrimes#include <sys/stat.h>
351541Srgrimes#include <sys/types.h>
3622521Sdyson#include <sys/file.h>
371541Srgrimes
3822521Sdyson/* Macros */
3922521Sdyson#define SUCCESS	(0)
4022521Sdyson#define	FAIL	(-1)
4122521Sdyson
4222521Sdyson#ifndef TRUE
4350477Speter#define TRUE	(1)
441541Srgrimes#endif
451541Srgrimes
461541Srgrimes#ifndef FALSE
471541Srgrimes#define FALSE	(0)
481541Srgrimes#endif
491541Srgrimes
501541Srgrimes#define YES		2
511541Srgrimes#define NO		1
521541Srgrimes
531541Srgrimes/* Usually "rm", but often "echo" during debugging! */
541541Srgrimes#define REMOVE_CMD	"rm"
5535256Sdes
561541Srgrimes/* Usually "rm", but often "echo" during debugging! */
571541Srgrimes#define RMDIR_CMD	"rmdir"
581541Srgrimes
591541Srgrimes/* Where we put logging information */
601541Srgrimes#define LOG_DIR		"/var/db/pkg"
611541Srgrimes
621541Srgrimes/* The names of our "special" files */
631541Srgrimes#define CONTENTS_FNAME	"+CONTENTS"
641541Srgrimes#define COMMENT_FNAME	"+COMMENT"
651541Srgrimes#define DESC_FNAME	"+DESC"
661541Srgrimes#define INSTALL_FNAME	"+INSTALL"
671541Srgrimes#define DEINSTALL_FNAME	"+DEINSTALL"
681541Srgrimes#define REQUIRE_FNAME	"+REQUIRE"
691541Srgrimes
701541Srgrimes#define CMD_CHAR	'@'	/* prefix for extended PLIST cmd */
711541Srgrimes
721541Srgrimes/* The name of the "prefix" environment variable given to scripts */
731541Srgrimes#define PKG_PREFIX_VNAME	"PKG_PREFIX"
741541Srgrimes
751541Srgrimesenum _plist_t {
761541Srgrimes    PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
771541Srgrimes    PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT,
781541Srgrimes    PLIST_IGNORE, PLIST_NAME, PLIST_UNEXEC, PLIST_SRC
791541Srgrimes};
801541Srgrimestypedef enum _plist_t plist_t;
811541Srgrimes
821541Srgrimes/* Types */
831541Srgrimestypedef unsigned int Boolean;
841541Srgrimes
8526963Salexstruct _plist {
861541Srgrimes    struct _plist *prev, *next;
871541Srgrimes    char *name;
881541Srgrimes    Boolean marked;
891541Srgrimes    plist_t type;
901541Srgrimes};
911541Srgrimestypedef struct _plist *PackingList;
921541Srgrimes
931541Srgrimesstruct _pack {
941541Srgrimes    struct _plist *head, *tail;
951541Srgrimes};
9622521Sdysontypedef struct _pack Package;
9722521Sdyson
9822521Sdyson/* Prototypes */
9922521Sdyson/* Misc */
10022521Sdysonint		vsystem(const char *, ...);
1011541Srgrimesvoid		cleanup(int);
10222521Sdysonchar		*make_playpen(char *, size_t);
10322521Sdysonvoid		leave_playpen(void);
10422521Sdysonchar		*where_playpen(void);
10522521Sdyson
10622521Sdyson/* String */
10722521Sdysonchar 		*get_dash_string(char **);
10822521Sdysonchar		*copy_string(char *);
10922521SdysonBoolean		suffix(char *, char *);
11022521Sdysonvoid		nuke_suffix(char *);
1111541Srgrimesvoid		str_lowercase(char *);
1121541Srgrimeschar		*basename_of(char *);
1131541Srgrimes
1141541Srgrimes/* File */
1151541SrgrimesBoolean		fexists(char *);
1161541SrgrimesBoolean		isdir(char *);
1171541SrgrimesBoolean		isempty(char *);
1181541Srgrimeschar		*get_file_contents(char *);
1191541Srgrimesvoid		write_file(char *, char *);
1201541Srgrimesvoid		copy_file(char *, char *, char *);
1211541Srgrimesvoid		copy_hierarchy(char *, char *, Boolean);
1221541Srgrimesint		delete_hierarchy(char *, Boolean);
1231541Srgrimesint		unpack(char *, char *);
1241541Srgrimesvoid		format_cmd(char *, char *, char *, char *);
1258876Srgrimes
1261541Srgrimes/* Msg */
1271541Srgrimesvoid		upchuck(const char *);
1281541Srgrimesvoid		barf(const char *, ...);
1291541Srgrimesvoid		whinge(const char *, ...);
1301541SrgrimesBoolean		y_or_n(Boolean, const char *, ...);
1311541Srgrimes
1321541Srgrimes/* Packing list */
1331541SrgrimesPackingList	new_plist_entry(void);
1341541SrgrimesPackingList	last_plist(Package *);
1358876SrgrimesPackingList	find_plist(Package *, plist_t);
1361541Srgrimesvoid		plist_delete(Package *, Boolean, plist_t, char *);
1371541Srgrimesvoid		free_plist(Package *);
1381541Srgrimesvoid		mark_plist(Package *);
1391541Srgrimesvoid		csum_plist_entry(char *, PackingList);
1401541Srgrimesvoid		add_plist(Package *, plist_t, char *);
1411541Srgrimesvoid		add_plist_top(Package *, plist_t, char *);
1421541Srgrimesvoid		write_plist(Package *, FILE *);
1431541Srgrimesvoid		read_plist(Package *, FILE *);
1441541Srgrimesint		plist_cmd(char *, char **);
1451541Srgrimesint		delete_package(Boolean, Package *);
1461541Srgrimes
1471541Srgrimes/* For all */
1481541Srgrimesvoid		usage(const char *, const char *, ...);
1498876Srgrimesint		pkg_perform(char **);
1501541Srgrimes
1511541Srgrimes/* Externs */
1521541Srgrimesextern Boolean	Verbose;
1531541Srgrimesextern Boolean	Fake;
1541541Srgrimesextern int	AutoAnswer;
1558876Srgrimes
1561541Srgrimes#endif /* _INST_LIB_LIB_H_ */
1571541Srgrimes