/*		@(#)defs	7.1	(ULTRIX)	7/23/92			      */

/************************************************************************
 *									*
 *			Copyright (c) 1986,1987,1988,1989 by		*
 *		Digital Equipment Corporation, Maynard, MA		*
 *			All rights reserved.				*
 *									*
 *   This software is furnished under a license and may be used and	*
 *   copied  only  in accordance with the terms of such license and	*
 *   with the  inclusion  of  the  above  copyright  notice.   This	*
 *   software  or  any  other copies thereof may not be provided or	*
 *   otherwise made available to any other person.  No title to and	*
 *   ownership of the software is hereby transferred.			*
 *									*
 *   This software is  derived  from  software  received  from  the	*
 *   University    of   California,   Berkeley,   and   from   Bell	*
 *   Laboratories.  Use, duplication, or disclosure is  subject  to	*
 *   restrictions  under  license  agreements  with  University  of	*
 *   California and with AT&T.						*
 *									*
 *   The information in this software is subject to change  without	*
 *   notice  and should not be construed as a commitment by Digital	*
 *   Equipment Corporation.						*
 *									*
 *   Digital assumes no responsibility for the use  or  reliability	*
 *   of its software on equipment which is not supplied by Digital.	*
 *									*
 ************************************************************************/

/******************************************
*	Revision History
*
*	20-Sep-90   Lee R. Miller
*
*	made max args on exec 2047, fix for qar 5741
*
*	14-Apr-89	Tim N
*	Removed mips conditionals around MAXPATHLEN and includes for
*	param.h dir.h and signal.h.  Removed sys_siglist[] which is
*	not used.  Removed nopdir which is not used.  Removed EQ_*'s
*	which are not used.  Removed mips conditionals around firstod.
*	Added this comment block.  Added defines of POSIX_ON and SYSV_ON.
*	These values are used to turn on global flag sysvmode, POSIX_ON
*	acts just like SYSV except for special handling of SHELL and
*	MAKESHELL macro values.
********************************************/

#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/dir.h>
#include <signal.h>
#include <limits.h>
#ifndef MAXPATHLEN
#define MAXPATHLEN	1023
#endif MAXPATHLEN

#define NEWLINE	'\n'
#define CNULL	'\0'
#define BLANK	' '
#define TAB	'\t'
#define DOT	'.'
#define WIGGLE	'~'
#define AT	'@'
#define MINUS	'-'
#define EQUALS	'='
#define SLASH	'/'
#define STAR	'*'
#define LCURLY	'{'
#define RCURLY	'}'
#define LPAREN	'('
#define RPAREN	')'
#define LSQUAR	'['
#define RSQUAR	']'
#define QUESTN	'?'
#define KOLON	':'
#define SKOLON	';'
#define DOLLAR	'$'
#define GREATR	'>'
#define POUND	'#'
#define BACKSLASH	'\\'


/*
 *	Flags
 */

char *calloc_return;
#define ALLOC(x) (((calloc_return = calloc(1,sizeof(struct x))) ? \
		  (struct x *) calloc_return : \
		  (struct x *) fatal("out of memory")))


#define TURNON(a)	(Mflags |= (a))
#define TURNOFF(a)	(Mflags &= (~(a)))
#define IS_ON(a)	(Mflags&(a))
#define IS_OFF(a)	(!(IS_ON(a)))

#define DBUG	0000001		/* debug flag */
#define ENVOVER	0000002		/* environ overides file defines */
#define EXPORT	0000004		/* put current variable in environ */
#define PRTR	0000010		/* set `-p' flag */
#define SIL	0000020		/* set `-s' flag */
#define NOEX	0000040		/* set `-n' flag */
#define INTRULE	0000100		/* use internal rules */
#define TOUCH	0000200		/* set `-t' flag */
#define GET	0000400		/* do a $(GET) if file not found */
#define QUEST	0001000		/* set `-q' flag */
#define INARGS	0002000		/* currently reading cmd args */
#define IGNERR	0004000		/* set `-i' flag */
#define KEEPGO	0010000		/* set `-k' flag */
#define GF_KEEP	0020000		/* keep auto get files */
#define MH_DEP	0040000		/* use old question about whether cmd exists */
#define MEMMAP	0100000		/* print memory map */

#define SYSV_ON		1	/* turn on sysv mode of handling 'SHELL' */
#define POSIX_ON	2	/* sysv mode with POSIX handling of 'SHELL' */

typedef char *CHARSTAR;
typedef int  *INTSTAR;
typedef long int TIMETYPE;
typedef struct gothead *GOTHEAD;
typedef struct gotf *GOTF;
typedef struct chain *CHAIN;
typedef struct dirhdr *DIRHDR;
typedef struct opendir *OPENDIR;
typedef struct pattern *PATTERN;
typedef struct varblock *VARBLOCK;
typedef struct shblock *SHBLOCK;
typedef struct depblock *DEPBLOCK;
typedef struct lineblock *LINEBLOCK;
typedef struct nameblock *NAMEBLOCK;

extern CHARSTAR *environ;
extern int Mflags;
extern FILE *fin;
extern CHARSTAR *linesptr;
extern int sysvmode;

/*
 *	flags for get()
 */
#define CD	0
#define NOCD	1


#define max(a,b)	((a)>(b)?(a):(b))
#define SHELLCOM	"/bin/sh"

#ifdef unix
/*  to install metering, add a statement like */
/*******
#define METERFILE "/usr/sif/make/Meter"
******/
/* to turn metering on, set external variable meteron to 1 */
#endif

/* define FSTATIC to be static on systems with C compilers
   supporting file-static; otherwise define it to be null
*/
#define FSTATIC static

#define NO 0
#define YES 1

#define catstr(p,str)	{register char *ptr;\
			 for(ptr=(str);*ptr;)*(p)++ = *ptr++;}

#define equal(a,b)	(a[0] == b[0] ? !strcmp((a),(b)) : NO )
#define any(a,b)	strchr( (a), (b) )
#define HASHSIZE ((1<<13)-1)	/* must be 2**n -1  so that hashloc() works */
#define NLEFTS 512
#define INMAX 20480
#define OUTMAX 20480
#define MAXODIR	10
#define MAXEXECARGS 2048		/* maximum size of argv on an exec */

NAMEBLOCK hashtab[HASHSIZE+1];
#define srchname(s)	((NAMEBLOCK) hashtab[hashloc(s)])

#define ALLDEPS  1
#define SOMEDEPS 2

#define META 01
#define TERMINAL 02
extern char funny[128];



extern int sigivalue;
extern int sigqvalue;
extern int waitpid;
extern int ndocoms;
extern int okdel;
extern CHARSTAR prompt;
extern char junkname[];
extern char RELEASE[];



struct nameblock
{
	NAMEBLOCK nextname;		/* pointer to next nameblock */
	NAMEBLOCK backname;		/* pointer to predecessor */
	CHARSTAR namep;		/* ASCII name string */
	CHARSTAR alias;		/* ASCII alias (when namep translates to another
				 * pathstring.
				 */
	LINEBLOCK linep; /* pointer to dependents */
	int done:3;		/* flag used to tell when finished */
	int septype:3;		/* distinguishes between single and double : */
	int rundep:1;		/* flag indicating runtime translation done */
	TIMETYPE modtime;	/* set by exists() */
};


extern NAMEBLOCK mainname ;
extern NAMEBLOCK firstname;

struct lineblock
{
	LINEBLOCK nextline;
	DEPBLOCK depp;
	SHBLOCK shp;
};

extern LINEBLOCK sufflist;

struct depblock
{
	DEPBLOCK nextdep;
	NAMEBLOCK depname;
};

struct shblock
{
	SHBLOCK nextsh;
	CHARSTAR shbp;
};

struct varblock
{
	VARBLOCK nextvar;
	CHARSTAR varname;
	CHARSTAR varval;
	int noreset:1;
	int used:1;
	int envflg:1;
	int v_aflg:1;
};

extern VARBLOCK firstvar;

struct pattern
{
	PATTERN nextpattern;
	CHARSTAR patval;
};

extern PATTERN firstpat;

struct	dirhdr
{
	DIRHDR nextdirhdr;
	DIR * dirfc;
	CHARSTAR dirn;
};
struct	opendir
{
	OPENDIR nextopendir;
	DIR * dirfc;
	CHARSTAR dirn;
};
extern DIRHDR firstdir;
#define firstod ((OPENDIR)firstdir)

struct chain
{
	CHAIN nextchain;
	CHARSTAR datap;
};

/*
 *	The following two structures are used to cleanup after
 *	`make' does an automatic get of a file. See get() and
 *	cleanup().
 */
struct gotf			/* list of files */
{
	GOTF gnextp;
	CHARSTAR gnamep;
};

struct gothead			/* first member of list of files */
{
	GOTF gnextp;
	CHARSTAR gnamep;
	GOTF endp;
};

extern char Nullstr[];
extern CHARSTAR badptr;
CHARSTAR copys();
CHARSTAR copstr();
CHARSTAR concat();
CHARSTAR colontrans();
CHARSTAR dftrans();
CHARSTAR straightrans();
CHARSTAR mkqlist();
CHARSTAR findfl();
CHARSTAR addstars();
CHARSTAR strshift();
INTSTAR  intalloc();
VARBLOCK varptr();
VARBLOCK srchvar();
TIMETYPE prestime(), exists();
DEPBLOCK srchdir();
NAMEBLOCK makename();
LINEBLOCK runtime();
CHARSTAR strrchr();
CHARSTAR strchr();
CHARSTAR sdot();
CHARSTAR trysccs();
CHARSTAR calloc();
