Filewatcher File Search
FTP Search
  
Directory 
  
Content Search 
   
pkg://lfu-3.1-5.src.rpm:719942/lfu-3.1.5.tar.gz  info  downloads

lfu-3.1.5/src/Makefile.in   644  75362  74430       20777  6514420241  10375 # Makefile.in generated automatically by automake 1.0 from Makefile.am

# Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.

# Process this file with `automake' to create `makefile.in'


SHELL = /bin/sh

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include

pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@

top_builddir = ..

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@

bin_PROGRAMS = lfu
lfu_SOURCES = avl.c cache.c eval.c lfu.c misc.c \
              parse.y pass1.c pass2.c scan.l stats.c
lfu_LDADD = ../libre/libre.a @AWDLIBS@
lfu_DEPENDENCIES = ../libre/libre.a @AWDLIBS@

libexec_PROGRAMS = xlfumon
xlfumon_SOURCES = xlfumon.c
xlfumon_LDADD = @XLIBS@

INCLUDES = -I../libre @XINCS@ @X_CFLAGS@

EXTRA_DIST = parse.y.in

noinst_HEADERS = avl.h cache.h eval.h misc.h parse.h pass1.h pass2.h \
                 scan.h stats.h xlfumon.xbm alloca.c
mkinstalldirs = $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
PROGRAMS = $(bin_PROGRAMS) $(libexec_PROGRAMS)


CC = @CC@
LEX = @LEX@
YACC = @YACC@

DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@

COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
LINK = $(CC) $(LDFLAGS) -o $@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
lfu_OBJECTS = avl.o cache.o eval.o lfu.o misc.o parse.o pass1.o pass2.o \
scan.o stats.o
EXTRA_lfu_SOURCES =
xlfumon_OBJECTS = xlfumon.o
EXTRA_xlfumon_SOURCES =
HEADERS = $(noinst_HEADERS)

DIST_COMMON = Makefile.am Makefile.in parse.c scan.c


PACKAGE = @PACKAGE@
VERSION = @VERSION@

DISTFILES = $(DIST_COMMON) $(SOURCES) $(BUILT_SOURCES) $(HEADERS) \
	$(TEXINFOS) $(INFOS) $(MANS) $(EXTRA_DIST) $(DATA)
DEP_DISTFILES = $(DIST_COMMON) $(SOURCES) $(BUILT_SOURCES) $(HEADERS) \
	$(TEXINFOS) $(INFO_DEPS) $(MANS) $(EXTRA_DIST) $(DATA)

TAR = tar
SOURCES = $(lfu_SOURCES) $(xlfumon_SOURCES)
OBJECTS = $(lfu_OBJECTS) $(xlfumon_OBJECTS)

default: all


$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in
	cd $(top_srcdir) && automake $(subdir)/Makefile

Makefile: $(top_builddir)/config.status Makefile.in
	cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status
parse.y: $(top_builddir)/config.status parse.y.in
	cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status

mostlyclean-binPROGRAMS:

clean-binPROGRAMS:
	rm -f $(bin_PROGRAMS)

distclean-binPROGRAMS:

maintainer-clean-binPROGRAMS:

install-binPROGRAMS: $(bin_PROGRAMS)
	$(mkinstalldirs) $(bindir)
	list="$(bin_PROGRAMS)"; for p in $$list; do \
	  if test -f $$p; then \
	    $(INSTALL_PROGRAM) $$p $(bindir)/`echo $$p|sed '$(transform)'`; \
	  else :; fi; \
	done

uninstall-binPROGRAMS:
	list="$(bin_PROGRAMS)"; for p in $$list; do \
	  rm -f $(bindir)/`echo $$p|sed '$(transform)'`; \
	done

mostlyclean-libexecPROGRAMS:

clean-libexecPROGRAMS:
	rm -f $(libexec_PROGRAMS)

distclean-libexecPROGRAMS:

maintainer-clean-libexecPROGRAMS:

install-libexecPROGRAMS: $(libexec_PROGRAMS)
	$(mkinstalldirs) $(libexecdir)
	list="$(libexec_PROGRAMS)"; for p in $$list; do \
	  if test -f $$p; then \
	    $(INSTALL_PROGRAM) $$p $(libexecdir)/`echo $$p|sed '$(transform)'`; \
	  else :; fi; \
	done

uninstall-libexecPROGRAMS:
	list="$(libexec_PROGRAMS)"; for p in $$list; do \
	  rm -f $(libexecdir)/`echo $$p|sed '$(transform)'`; \
	done

.c.o:
	$(COMPILE) $<

mostlyclean-compile:
	rm -f *.o core

clean-compile:

distclean-compile:
	rm -f *.tab.c

maintainer-clean-compile:
$(lfu_OBJECTS): ../config.h

lfu: $(lfu_OBJECTS) $(lfu_DEPENDENCIES)
	$(LINK) $(lfu_OBJECTS) $(lfu_LDADD) $(LIBS)
$(xlfumon_OBJECTS): ../config.h

xlfumon: $(xlfumon_OBJECTS) $(xlfumon_DEPENDENCIES)
	$(LINK) $(xlfumon_OBJECTS) $(xlfumon_LDADD) $(LIBS)

ID: $(HEADERS) $(SOURCES)
	here=`pwd` && cd $(srcdir) && mkid -f$$here/ID $(SOURCES) $(HEADERS)

tags: TAGS

TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES)
	here=`pwd` && cd $(srcdir) && etags $(ETAGS_ARGS) $(SOURCES) $(HEADERS) -o $$here/TAGS

mostlyclean-tags:

clean-tags:

distclean-tags:
	rm -f TAGS ID

maintainer-clean-tags:

subdir = src
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
distdir: $(DEP_DISTFILES)
	@for file in `cd $(srcdir) && echo $(DISTFILES)`; do \
	  test -f $(distdir)/$$file \
	  || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \
	  || cp -p $(srcdir)/$$file $(distdir)/$$file; \
	done
alloca.o: alloca.c
avl.o: avl.c misc.h avl.h
cache.o: cache.c misc.h avl.h eval.h ../libre/regexp.h stats.h \
 tokens.h pass2.h cache.h
eval.o: eval.c misc.h avl.h eval.h ../libre/regexp.h cache.h
lfu.o: lfu.c misc.h mon.h eval.h ../libre/regexp.h parse.h pass1.h \
 pass2.h stats.h avl.h cache.h
misc.o: misc.c misc.h stats.h alloca.c
parse.o: parse.c misc.h eval.h ../libre/regexp.h scan.h avl.h cache.h \
 parse.h
pass1.o: pass1.c misc.h eval.h ../libre/regexp.h avl.h stats.h pass2.h \
 cache.h pass1.h
pass2.o: pass2.c misc.h eval.h ../libre/regexp.h avl.h pass1.h stats.h \
 cache.h pass2.h
scan.o: scan.c misc.h tokens.h scan.h toklist.h
stats.o: stats.c misc.h mon.h avl.h eval.h ../libre/regexp.h cache.h \
 stats.h
xlfumon.o: xlfumon.c xlfumon.xbm

info:

dvi:

check: all

installcheck:

install-exec: install-binPROGRAMS install-libexecPROGRAMS

install-data: 

install: install-exec install-data all
	@:

uninstall: uninstall-binPROGRAMS uninstall-libexecPROGRAMS

all: $(PROGRAMS) $(HEADERS) Makefile

install-strip:
	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
installdirs:
	$(mkinstalldirs)  $(bindir) $(libexecdir)


mostlyclean-generic:
	test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)

clean-generic:
	test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)

distclean-generic:
	rm -f Makefile $(DISTCLEANFILES)
	rm -f config.cache config.log $(CONFIG_HEADER) stamp-h

maintainer-clean-generic:
	test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
	test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
mostlyclean:  mostlyclean-binPROGRAMS mostlyclean-libexecPROGRAMS \
		mostlyclean-compile mostlyclean-tags \
		mostlyclean-generic

clean:  clean-binPROGRAMS clean-libexecPROGRAMS clean-compile clean-tags \
		clean-generic mostlyclean 

distclean:  distclean-binPROGRAMS distclean-libexecPROGRAMS \
		distclean-compile distclean-tags distclean-generic \
		clean 
	rm -f config.status

maintainer-clean:  maintainer-clean-binPROGRAMS \
		maintainer-clean-libexecPROGRAMS \
		maintainer-clean-compile maintainer-clean-tags \
		maintainer-clean-generic distclean 
	@echo "This command is intended for maintainers to use;"
	@echo "it deletes files that may require special tools to rebuild."

.PHONY: default mostlyclean-binPROGRAMS distclean-binPROGRAMS \
clean-binPROGRAMS maintainer-clean-binPROGRAMS uninstall-binPROGRAMS \
install-binPROGRAMS mostlyclean-libexecPROGRAMS \
distclean-libexecPROGRAMS clean-libexecPROGRAMS \
maintainer-clean-libexecPROGRAMS uninstall-libexecPROGRAMS \
install-libexecPROGRAMS mostlyclean-compile distclean-compile \
clean-compile maintainer-clean-compile tags mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir info dvi check \
installcheck install-exec install-data install uninstall all \
installdirs mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean


parse.c \
tokens.h	: parse.y
		@YACC@ -d parse.y
		mv y.tab.c parse.c
		mv y.tab.h tokens.h

scan.c		: scan.l
		@LEX@ scan.l
		mv lex.yy.c scan.c

# This works out the name of the monitor program

lfu.o		: mon.h
stats.o		: mon.h
mon.h		: ../config.status
		echo "#define MONITOR_PROG \"${libexecdir}/xlfumon\"" >mon.h

# This makes a list of token names for debugging

scan.o		: toklist.h
toklist.h       : tokens.h
		@echo making token list
		@sed -e 's/# /#/' <tokens.h | \
			awk '/T_/{ printf " case %s: return \"%s\";\n", \
		    	$$2, $$2; }' >toklist.h
.SUFFIXES:
.SUFFIXES: .c .o

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
lfu-3.1.5/src/Makefile.am   644  75362  74430        2115  6510207073  10330 # Process this file with `automake' to create `makefile.in'

bin_PROGRAMS = lfu
lfu_SOURCES = avl.c cache.c eval.c lfu.c misc.c \
              parse.y pass1.c pass2.c scan.l stats.c
lfu_LDADD = ../libre/libre.a @AWDLIBS@
lfu_DEPENDENCIES = ../libre/libre.a @AWDLIBS@

libexec_PROGRAMS = xlfumon
xlfumon_SOURCES = xlfumon.c
xlfumon_LDADD = @XLIBS@

INCLUDES = -I../libre @XINCS@ @X_CFLAGS@

EXTRA_DIST = parse.y.in

noinst_HEADERS = avl.h cache.h eval.h misc.h parse.h pass1.h pass2.h \
                 scan.h stats.h xlfumon.xbm alloca.c

parse.c \
tokens.h	: parse.y
		@YACC@ -d parse.y
		mv y.tab.c parse.c
		mv y.tab.h tokens.h

scan.c		: scan.l
		@LEX@ scan.l
		mv lex.yy.c scan.c

# This works out the name of the monitor program

lfu.o		: mon.h
stats.o		: mon.h
mon.h		: ../config.status
		echo "#define MONITOR_PROG \"${libexecdir}/xlfumon\"" >mon.h

# This makes a list of token names for debugging

scan.o		: toklist.h
toklist.h       : tokens.h
		@echo making token list
		@sed -e 's/# /#/' <tokens.h | \
			awk '/T_/{ printf " case %s: return \"%s\";\n", \
		    	$$2, $$2; }' >toklist.h
lfu-3.1.5/src/parse.c   644  75362  74430      155350  6514416410   7625 
/*  A Bison parser, made from parse.y
 by  GNU Bison version 1.25
  */

#define YYBISON 1  /* Identify Bison output.  */

#define	T_DEFAULT	258
#define	T_STRING	259
#define	T_LBR	260
#define	T_RBR	261
#define	T_LPAR	262
#define	T_RPAR	263
#define	T_LSQ	264
#define	T_RSQ	265
#define	T_EQ	266
#define	T_NEQ	267
#define	T_AND	268
#define	T_OR	269
#define	T_NOT	270
#define	T_TILDE	271
#define	T_SEMI	272
#define	T_ELSE	273
#define	T_GT	274
#define	T_LT	275
#define	T_NAME	276
#define	T_OWNER	277
#define	T_GROUP	278
#define	T_TYPE	279
#define	T_PATH	280
#define	T_AGE	281
#define	T_MODE	282
#define	T_ACCESS	283
#define	T_SIZE	284
#define	T_EXISTS	285
#define	T_REBOOT	286
#define	T_ERROR	287
#define	T_CHGRP	288
#define	T_CHOWN	289
#define	T_LOGALL	290
#define	T_INHERIT	291
#define	T_CDF	292
#define	T_STATS	293
#define	T_UPDATE	294
#define	T_PRESERVE	295
#define	T_DELETE	296
#define	T_IGNORE	297
#define	T_SOURCE	298
#define	T_WARN	299
#define	T_LNK	300
#define	T_KEEP	301
#define	T_LOG	302
#define	T_FORCE	303
#define	T_FILL	304
#define	T_CHMOD	305
#define	T_NEWER	306
#define	T_EXEC	307
#define	T_NEWTIME	308
#define	T_SHADOW	309
#define	T_FOLLOW	310
#define	T_COMPRESS	311
#define	T_AUTO	312
#define	T_NOMOUNT	313
#define	T_CACHE	314
#define	T_CACHEFILE	315
#define	T_CACHEMINSIZE	316
#define	T_CACHEMINVALUE	317
#define	T_CACHEFILL	318
#define	T_CACHEMINFREE	319
#define	T_NOIDCHECK	320

#line 1 "parse.y"

/**************************************************************************

  The Program parser.

  $Author: paul $
  $Revision: 1.3 $
  $Date: 1998/03/31 15:39:07 $

  Copyright (c) 1992 by the University of Edinburgh
  Laboratory for the Foundations of Computer Science
  Department of Computer Science
  Written by Paul Anderson.

  Permission is granted to anyone to use this software for any
  purpose on any computer system, and to redistribute it freely,
  subject to the following restrictions:

  The University of Edinburgh makes no representations about the
  suitability of this software for any purpose.  It is
  provided "as is" without express or implied warranty.

  The origin of this software must not be misrepresented, either by
  explicit claim or by omission, and this copyright notice must appear in
  all copies of the software. Altered versions must be plainly marked
  as such, and must not be misrepresented as being the original software.

  The name of the University of Edinburgh must not be used in
  advertising or publicity pertaining to distribution of the software
  without specific, written prior permission. 
 
**************************************************************************/

#define _PARSE_C

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include "misc.h"
#include <string.h>
#include "eval.h"
#include "scan.h"
#include "avl.h"
#ifdef LFU_CACHE
#include "cache.h"
#endif
#include "parse.h"

#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#else
extern char *alloca();
#endif

extern int yyerror();
extern int yylex();

/**************************************************************************
  Verbose error reporting
**************************************************************************/

#ifdef YYDEBUG
#undef HAVE_VERBOSE_PARSER_MSGS
#endif

#ifdef HAVE_VERBOSE_PARSER_MSGS

#define yyerror(msg) VerboseErr(yystate,msg)
#define xmalloc(n) malloc(n)

#ifdef PARSE_DEBUG
#define TokenClass(a,b) b
#else
#define TokenClass(a,b) a
#endif

/* Beware - the order of these strings must be the same as the order in
   which the tokens are declared */

static char *yytname[] = {
  TokenClass(NOSTR,"T_$"),
  TokenClass(NOSTR,"T_error"),
  TokenClass(NOSTR,"T_$illegal"),
  TokenClass("default","T_DEFAULT"),
  TokenClass("string","T_STRING"),
  TokenClass("block","T_LBR"),
  TokenClass("'}'","T_RBR"),
  TokenClass("condition","T_LPAR"),
  TokenClass("')'","T_RPAR"),
  TokenClass("[","T_LSQ"),
  TokenClass("']'","T_RSQ"),
  TokenClass("'='","T_EQ"),
  TokenClass("'!='","T_NEQ"),
  TokenClass("operator","T_AND"),
  TokenClass("operator","T_OR"),
  TokenClass("condition","T_NOT"),
  TokenClass("action","T_TILDE"),
  TokenClass("';'","T_SEMI"),
  TokenClass("'else'","T_ELSE"),
  TokenClass("'>'","T_GT"),
  TokenClass("'<'","T_LT"),
  TokenClass("condition","T_NAME"),
  TokenClass("condition","T_OWNER"),
  TokenClass("condition","T_GROUP"),
  TokenClass("condition","T_TYPE"),
  TokenClass("condition","T_PATH"),
  TokenClass("condition","T_AGE"),
  TokenClass("condition","T_MODE"),
  TokenClass("condition","T_ACCESS"),
  TokenClass("condition","T_SIZE"),
  TokenClass("condition","T_EXISTS"),
  TokenClass("condition","T_REBOOT"),
  TokenClass("action","T_ERROR"),
  TokenClass("action","T_CHGRP"),
  TokenClass("action","T_CHOWN"),
  TokenClass("action","T_LOGALL"),
  TokenClass("action","T_INHERIT"),
  TokenClass("action","T_CDF"),
  TokenClass("action","T_STATS"),
  TokenClass("action","T_UPDATE"),
  TokenClass("action","T_PRESERVE"),
  TokenClass("action","T_DELETE"),
  TokenClass("action","T_IGNORE"),
  TokenClass("action","T_SOURCE"),
  TokenClass("action","T_WARN"),
  TokenClass("action","T_LNK"),
  TokenClass("action","T_KEEP"),
  TokenClass("action","T_LOG"),
  TokenClass("action","T_FORCE"),
  TokenClass("action","T_FILL"),
  TokenClass("action","T_CHMOD"),
  TokenClass("action","T_NEWER"),
  TokenClass("action","T_EXEC"),
  TokenClass("action","T_NEWTIME"),
  TokenClass("action","T_SHADOW"),
  TokenClass("action","T_FOLLOW"),
  TokenClass("action","T_COMPRESS"),
  TokenClass("action","T_AUTO"),
  TokenClass("option","T_NOMOUNT"),
  TokenClass("action","T_CACHE"),
  TokenClass("option","T_CACHEFILE"),
  TokenClass("option","T_CACHEMINSIZE"),
  TokenClass("option","T_CACHEMINFREE"),
  TokenClass("option","T_CACHEMINVALUE"),
  TokenClass("option","T_CACHEFILL"),
  TokenClass("option","T_NOIDCHECK"),
};

#endif


#line 159 "parse.y"
typedef union {
  char *string;
  struct _PROG *prog;
  int none;
} YYSTYPE;
#include <stdio.h>

#ifndef __cplusplus
#ifndef __STDC__
#define const
#endif
#endif



#define	YYFINAL		186
#define	YYFLAG		-32768
#define	YYNTBASE	66

#define YYTRANSLATE(x) ((unsigned)(x) <= 320 ? yytranslate[x] : 82)

static const char yytranslate[] = {     0,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
     6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
    16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
    26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
    36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
    46,    47,    48,    49,    50,    51,    52,    53,    54,    55,
    56,    57,    58,    59,    60,    61,    62,    63,    64,    65
};

#if YYDEBUG != 0
static const short yyprhs[] = {     0,
     0,     1,     3,     5,     7,    10,    13,    18,    20,    23,
    26,    29,    31,    34,    37,    41,    44,    49,    51,    55,
    59,    61,    64,    68,    73,    78,    82,    86,    91,    96,
   101,   106,   111,   114,   119,   124,   129,   134,   139,   144,
   149,   154,   158,   162,   167,   170,   175,   176,   180,   186,
   188,   191,   194,   197,   200,   202,   203,   206,   208,   211,
   213,   215,   217,   219,   221,   224,   226,   229,   231,   234,
   236,   239,   241,   244,   246,   249,   251,   254,   256,   259,
   261,   264,   266,   269,   271,   274,   276,   279,   281,   284,
   286,   289,   291,   294,   297,   300,   303,   306,   309,   312,
   315,   318,   321,   324,   327,   332,   335,   338,   341,   344,
   347,   350,   352
};

static const short yyrhs[] = {    -1,
    67,     0,    68,     0,    72,     0,    67,    68,     0,    67,
    72,     0,     3,     5,    69,     6,     0,    70,     0,    70,
    69,     0,    77,    17,     0,    81,    17,     0,    72,     0,
    71,    72,     0,    81,    17,     0,     5,    71,     6,     0,
    73,    72,     0,    73,    72,    18,    72,     0,    74,     0,
    73,    13,    73,     0,    73,    14,    73,     0,    75,     0,
    15,    74,     0,     7,    73,     8,     0,    22,    76,    11,
    78,     0,    23,    76,    11,    78,     0,    21,    11,    78,
     0,    25,    11,    78,     0,    24,    76,    11,    78,     0,
    27,    76,    11,    78,     0,    26,    76,    19,    78,     0,
    26,    76,    11,    78,     0,    26,    76,    20,    78,     0,
    31,    76,     0,    28,    76,    19,    78,     0,    28,    76,
    11,    78,     0,    28,    76,    20,    78,     0,    29,    76,
    19,    78,     0,    29,    76,    11,    78,     0,    29,    76,
    20,    78,     0,    22,    76,    12,    78,     0,    23,    76,
    12,    78,     0,    21,    12,    78,     0,    25,    12,    78,
     0,    24,    76,    12,    78,     0,    30,    76,     0,    27,
    76,    12,    78,     0,     0,     9,    78,    10,     0,     9,
    78,    11,    78,    10,     0,    58,     0,    60,    78,     0,
    61,    78,     0,    64,    78,     0,    62,    78,     0,    63,
     0,     0,    79,     4,     0,    78,     0,    80,    78,     0,
    39,     0,    40,     0,    41,     0,    42,     0,    45,     0,
    16,    45,     0,    54,     0,    16,    54,     0,    53,     0,
    16,    53,     0,    46,     0,    16,    46,     0,    47,     0,
    16,    47,     0,    35,     0,    16,    35,     0,    65,     0,
    16,    65,     0,    48,     0,    16,    48,     0,    49,     0,
    16,    49,     0,    36,     0,    16,    36,     0,    37,     0,
    16,    37,     0,    38,     0,    16,    38,     0,    51,     0,
    16,    51,     0,    55,     0,    16,    55,     0,    56,     0,
    16,    56,     0,    50,    80,     0,    16,    50,     0,    52,
    80,     0,    16,    52,     0,    57,    80,     0,    16,    57,
     0,    32,    80,     0,    16,    32,     0,    44,    80,     0,
    16,    44,     0,    43,    78,     0,    43,    78,    11,    78,
     0,    16,    43,     0,    34,    78,     0,    16,    34,     0,
    33,    78,     0,    16,    33,     0,    59,    78,     0,    59,
     0,    16,    59,     0
};

#endif

#if YYDEBUG != 0
static const short yyrline[] = { 0,
   207,   209,   212,   214,   216,   218,   221,   224,   226,   229,
   231,   234,   236,   239,   241,   243,   245,   248,   250,   252,
   255,   257,   259,   262,   264,   266,   268,   270,   272,   274,
   276,   278,   280,   282,   284,   286,   288,   290,   292,   294,
   296,   298,   300,   302,   304,   306,   309,   311,   313,   316,
   318,   324,   330,   336,   342,   349,   350,   352,   354,   357,
   359,   361,   363,   365,   367,   369,   371,   373,   375,   377,
   379,   381,   383,   385,   387,   389,   391,   393,   395,   397,
   399,   401,   403,   405,   407,   409,   411,   413,   415,   417,
   419,   421,   423,   425,   427,   429,   431,   433,   435,   437,
   439,   441,   443,   445,   447,   449,   451,   453,   455,   457,
   459,   465,   471
};
#endif


#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)

static const char * const yytname[] = {   "$","error","$undefined.","T_DEFAULT",
"T_STRING","T_LBR","T_RBR","T_LPAR","T_RPAR","T_LSQ","T_RSQ","T_EQ","T_NEQ",
"T_AND","T_OR","T_NOT","T_TILDE","T_SEMI","T_ELSE","T_GT","T_LT","T_NAME","T_OWNER",
"T_GROUP","T_TYPE","T_PATH","T_AGE","T_MODE","T_ACCESS","T_SIZE","T_EXISTS",
"T_REBOOT","T_ERROR","T_CHGRP","T_CHOWN","T_LOGALL","T_INHERIT","T_CDF","T_STATS",
"T_UPDATE","T_PRESERVE","T_DELETE","T_IGNORE","T_SOURCE","T_WARN","T_LNK","T_KEEP",
"T_LOG","T_FORCE","T_FILL","T_CHMOD","T_NEWER","T_EXEC","T_NEWTIME","T_SHADOW",
"T_FOLLOW","T_COMPRESS","T_AUTO","T_NOMOUNT","T_CACHE","T_CACHEFILE","T_CACHEMINSIZE",
"T_CACHEMINVALUE","T_CACHEFILL","T_CACHEMINFREE","T_NOIDCHECK","program","section",
"defblock","deflist","default","block","statement","condition","term","primary",
"arg","option","string","@1","stringlist","action", NULL
};
#endif

static const short yyr1[] = {     0,
    66,    66,    67,    67,    67,    67,    68,    69,    69,    70,
    70,    71,    71,    72,    72,    72,    72,    73,    73,    73,
    74,    74,    74,    75,    75,    75,    75,    75,    75,    75,
    75,    75,    75,    75,    75,    75,    75,    75,    75,    75,
    75,    75,    75,    75,    75,    75,    76,    76,    76,    77,
    77,    77,    77,    77,    77,    79,    78,    80,    80,    81,
    81,    81,    81,    81,    81,    81,    81,    81,    81,    81,
    81,    81,    81,    81,    81,    81,    81,    81,    81,    81,
    81,    81,    81,    81,    81,    81,    81,    81,    81,    81,
    81,    81,    81,    81,    81,    81,    81,    81,    81,    81,
    81,    81,    81,    81,    81,    81,    81,    81,    81,    81,
    81,    81,    81
};

static const short yyr2[] = {     0,
     0,     1,     1,     1,     2,     2,     4,     1,     2,     2,
     2,     1,     2,     2,     3,     2,     4,     1,     3,     3,
     1,     2,     3,     4,     4,     3,     3,     4,     4,     4,
     4,     4,     2,     4,     4,     4,     4,     4,     4,     4,
     4,     3,     3,     4,     2,     4,     0,     3,     5,     1,
     2,     2,     2,     2,     1,     0,     2,     1,     2,     1,
     1,     1,     1,     1,     2,     1,     2,     1,     2,     1,
     2,     1,     2,     1,     2,     1,     2,     1,     2,     1,
     2,     1,     2,     1,     2,     1,     2,     1,     2,     1,
     2,     1,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     4,     2,     2,     2,     2,     2,
     2,     1,     2
};

static const short yydefact[] = {     1,
     0,     0,     0,     0,     0,     0,    47,    47,    47,     0,
    47,    47,    47,    47,    47,    47,    56,    56,    56,    74,
    82,    84,    86,    60,    61,    62,    63,    56,    56,    64,
    70,    72,    78,    80,    56,    88,    56,    68,    66,    90,
    92,    56,    56,    76,     2,     3,     4,     0,    18,    21,
     0,     0,     0,    12,     0,    22,   101,   110,   108,    75,
    83,    85,    87,   106,   103,    65,    71,    73,    79,    81,
    95,    89,    97,    69,    67,    91,    93,    99,   113,    77,
    56,    56,    56,     0,     0,     0,    56,    56,     0,     0,
     0,     0,    45,    33,    58,     0,    56,   109,   107,   104,
    56,    56,    56,    56,   111,     5,     6,     0,     0,    16,
    14,    50,    56,    56,    56,    55,    56,     0,     8,     0,
     0,    15,    13,    23,    26,    42,     0,    56,    56,    56,
    56,    56,    56,    27,    43,    56,    56,    56,    56,    56,
    56,    56,    56,    56,    56,    56,    57,    59,    56,    19,
    20,     0,    51,    52,    54,    53,     7,     9,    10,    11,
    48,    56,    24,    40,    25,    41,    28,    44,    31,    30,
    32,    29,    46,    35,    34,    36,    38,    37,    39,   105,
    17,     0,    49,     0,     0,     0
};

static const short yydefgoto[] = {   184,
    45,    46,   118,   119,    53,    47,    48,    49,    50,    84,
   120,    95,    96,    97,    51
};

static const short yypact[] = {   131,
    22,   292,   393,   393,   -15,    -4,    36,    36,    36,    37,
    36,    36,    36,    36,    36,    36,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,    39,-32768,   131,-32768,-32768,   184,-32768,-32768,
    42,   334,   239,-32768,    44,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,    50,    56,    62,-32768,-32768,    -7,    64,
    -5,     5,-32768,-32768,-32768,    59,    52,-32768,-32768,    43,
    60,    61,    65,    66,-32768,-32768,-32768,   393,   393,    63,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,    73,   334,    71,
    72,-32768,-32768,-32768,-32768,-32768,    -1,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
    77,   292,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,    81,-32768,    92,    93,-32768
};

static const short yypgoto[] = {-32768,
-32768,    49,   -24,-32768,-32768,    -2,     0,    95,-32768,   347,
-32768,   -17,-32768,    18,   -47
};


#define	YYLAST		424


static const short yytable[] = {    54,
    98,    99,    55,   136,   121,   141,    81,    82,   161,   162,
   100,   137,   138,   142,   143,   144,    57,    58,    59,    60,
    61,    62,    63,   145,   146,   105,    52,    64,    65,    66,
    67,    68,    69,    70,    71,    72,    73,    74,    75,    76,
    77,    78,   107,    79,    83,   110,   101,    87,    88,    80,
   123,   124,   102,   149,   103,  -112,   108,   109,   111,   104,
   128,   129,   147,   125,   126,   127,   130,   131,  -100,   134,
   135,   121,   132,   133,   139,   140,  -102,   -94,   157,   148,
   152,   -96,   -98,   148,   148,   148,   148,   159,   160,   108,
   183,   185,   186,   106,   158,   153,   154,   155,    56,   156,
     0,     0,     0,     0,     0,     0,     0,   150,   151,     0,
   163,   164,   165,   166,   167,   168,     0,     0,   169,   170,
   171,   172,   173,   174,   175,   176,   177,   178,   179,     0,
     0,   180,     0,     1,     0,     2,     0,     3,     0,     0,
     0,     0,     0,     0,   182,     4,     5,     0,     0,   181,
     0,     6,     7,     8,     9,    10,    11,    12,    13,    14,
    15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
    25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
    35,    36,    37,    38,    39,    40,    41,    42,     2,    43,
     3,     0,     0,     0,     0,    44,   108,   109,     4,     5,
     0,     0,     0,     0,     6,     7,     8,     9,    10,    11,
    12,    13,    14,    15,    16,    17,    18,    19,    20,    21,
    22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
    32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
    42,     0,    43,     2,   122,     3,     0,     0,    44,     0,
     0,     0,     0,     4,     5,     0,     0,     0,     0,     6,
     7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
    17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
    27,    28,    29,    30,    31,    32,    33,    34,    35,    36,
    37,    38,    39,    40,    41,    42,     2,    43,     3,     0,
     0,     0,     0,    44,     0,     0,     4,     5,     0,     0,
     0,     0,     6,     7,     8,     9,    10,    11,    12,    13,
    14,    15,    16,    17,    18,    19,    20,    21,    22,    23,
    24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
    34,    35,    36,    37,    38,    39,    40,    41,    42,     5,
    43,     0,     0,     0,    85,    86,    44,    89,    90,    91,
    92,    93,    94,     0,     0,    17,    18,    19,    20,    21,
    22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
    32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
    42,   112,    43,   113,   114,   115,   116,   117,    44,     3,
     0,     0,     0,     0,     0,     0,     0,     4,     0,     0,
     0,     0,     0,     6,     7,     8,     9,    10,    11,    12,
    13,    14,    15,    16
};

static const short yycheck[] = {     2,
    18,    19,     3,    11,    52,    11,    11,    12,    10,    11,
    28,    19,    20,    19,    20,    11,    32,    33,    34,    35,
    36,    37,    38,    19,    20,    43,     5,    43,    44,    45,
    46,    47,    48,    49,    50,    51,    52,    53,    54,    55,
    56,    57,    45,    59,     9,    48,    29,    11,    12,    65,
    53,     8,    35,    11,    37,    17,    13,    14,    17,    42,
    11,    12,     4,    81,    82,    83,    11,    12,    17,    87,
    88,   119,    11,    12,    11,    12,    17,    17,     6,    97,
    18,    17,    17,   101,   102,   103,   104,    17,    17,    13,
    10,     0,     0,    45,   119,   113,   114,   115,     4,   117,
    -1,    -1,    -1,    -1,    -1,    -1,    -1,   108,   109,    -1,
   128,   129,   130,   131,   132,   133,    -1,    -1,   136,   137,
   138,   139,   140,   141,   142,   143,   144,   145,   146,    -1,
    -1,   149,    -1,     3,    -1,     5,    -1,     7,    -1,    -1,
    -1,    -1,    -1,    -1,   162,    15,    16,    -1,    -1,   152,
    -1,    21,    22,    23,    24,    25,    26,    27,    28,    29,
    30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
    40,    41,    42,    43,    44,    45,    46,    47,    48,    49,
    50,    51,    52,    53,    54,    55,    56,    57,     5,    59,
     7,    -1,    -1,    -1,    -1,    65,    13,    14,    15,    16,
    -1,    -1,    -1,    -1,    21,    22,    23,    24,    25,    26,
    27,    28,    29,    30,    31,    32,    33,    34,    35,    36,
    37,    38,    39,    40,    41,    42,    43,    44,    45,    46,
    47,    48,    49,    50,    51,    52,    53,    54,    55,    56,
    57,    -1,    59,     5,     6,     7,    -1,    -1,    65,    -1,
    -1,    -1,    -1,    15,    16,    -1,    -1,    -1,    -1,    21,
    22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
    32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
    42,    43,    44,    45,    46,    47,    48,    49,    50,    51,
    52,    53,    54,    55,    56,    57,     5,    59,     7,    -1,
    -1,    -1,    -1,    65,    -1,    -1,    15,    16,    -1,    -1,
    -1,    -1,    21,    22,    23,    24,    25,    26,    27,    28,
    29,    30,    31,    32,    33,    34,    35,    36,    37,    38,
    39,    40,    41,    42,    43,    44,    45,    46,    47,    48,
    49,    50,    51,    52,    53,    54,    55,    56,    57,    16,
    59,    -1,    -1,    -1,     8,     9,    65,    11,    12,    13,
    14,    15,    16,    -1,    -1,    32,    33,    34,    35,    36,
    37,    38,    39,    40,    41,    42,    43,    44,    45,    46,
    47,    48,    49,    50,    51,    52,    53,    54,    55,    56,
    57,    58,    59,    60,    61,    62,    63,    64,    65,     7,
    -1,    -1,    -1,    -1,    -1,    -1,    -1,    15,    -1,    -1,
    -1,    -1,    -1,    21,    22,    23,    24,    25,    26,    27,
    28,    29,    30,    31
};
/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
#line 3 "/usr/lib/bison.simple"

/* Skeleton output parser for bison,
   Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

/* As a special exception, when this file is copied by Bison into a
   Bison output file, you may use that output file without restriction.
   This special exception was added by the Free Software Foundation
   in version 1.24 of Bison.  */

#ifndef alloca
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not GNU C.  */
#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
#include <alloca.h>
#else /* not sparc */
#if defined (MSDOS) && !defined (__TURBOC__)
#include <malloc.h>
#else /* not MSDOS, or __TURBOC__ */
#if defined(_AIX)
#include <malloc.h>
 #pragma alloca
#else /* not MSDOS, __TURBOC__, or _AIX */
#ifdef __hpux
#ifdef __cplusplus
extern "C" {
void *alloca (unsigned int);
};
#else /* not __cplusplus */
void *alloca ();
#endif /* not __cplusplus */
#endif /* __hpux */
#endif /* not _AIX */
#endif /* not MSDOS, or __TURBOC__ */
#endif /* not sparc.  */
#endif /* not GNU C.  */
#endif /* alloca not defined.  */

/* This is the parser code that is written into each bison parser
  when the %semantic_parser declaration is not specified in the grammar.
  It was written by Richard Stallman by simplifying the hairy parser
  used when %semantic_parser is specified.  */

/* Note: there must be only one dollar sign in this file.
   It is replaced by the list of actions, each action
   as one case of the switch.  */

#define yyerrok		(yyerrstatus = 0)
#define yyclearin	(yychar = YYEMPTY)
#define YYEMPTY		-2
#define YYEOF		0
#define YYACCEPT	return(0)
#define YYABORT 	return(1)
#define YYERROR		goto yyerrlab1
/* Like YYERROR except do call yyerror.
   This remains here temporarily to ease the
   transition to the new meaning of YYERROR, for GCC.
   Once GCC version 2 has supplanted version 1, this can go.  */
#define YYFAIL		goto yyerrlab
#define YYRECOVERING()  (!!yyerrstatus)
#define YYBACKUP(token, value) \
do								\
  if (yychar == YYEMPTY && yylen == 1)				\
    { yychar = (token), yylval = (value);			\
      yychar1 = YYTRANSLATE (yychar);				\
      YYPOPSTACK;						\
      goto yybackup;						\
    }								\
  else								\
    { yyerror ("syntax error: cannot back up"); YYERROR; }	\
while (0)

#define YYTERROR	1
#define YYERRCODE	256

#ifndef YYPURE
#define YYLEX		yylex()
#endif

#ifdef YYPURE
#ifdef YYLSP_NEEDED
#ifdef YYLEX_PARAM
#define YYLEX		yylex(&yylval, &yylloc, YYLEX_PARAM)
#else
#define YYLEX		yylex(&yylval, &yylloc)
#endif
#else /* not YYLSP_NEEDED */
#ifdef YYLEX_PARAM
#define YYLEX		yylex(&yylval, YYLEX_PARAM)
#else
#define YYLEX		yylex(&yylval)
#endif
#endif /* not YYLSP_NEEDED */
#endif

/* If nonreentrant, generate the variables here */

#ifndef YYPURE

int	yychar;			/*  the lookahead symbol		*/
YYSTYPE	yylval;			/*  the semantic value of the		*/
				/*  lookahead symbol			*/

#ifdef YYLSP_NEEDED
YYLTYPE yylloc;			/*  location data for the lookahead	*/
				/*  symbol				*/
#endif

int yynerrs;			/*  number of parse errors so far       */
#endif  /* not YYPURE */

#if YYDEBUG != 0
int yydebug;			/*  nonzero means print parse trace	*/
/* Since this is uninitialized, it does not stop multiple parsers
   from coexisting.  */
#endif

/*  YYINITDEPTH indicates the initial size of the parser's stacks	*/

#ifndef	YYINITDEPTH
#define YYINITDEPTH 200
#endif

/*  YYMAXDEPTH is the maximum size the stacks can grow to
    (effective only if the built-in stack extension method is used).  */

#if YYMAXDEPTH == 0
#undef YYMAXDEPTH
#endif

#ifndef YYMAXDEPTH
#define YYMAXDEPTH 10000
#endif

/* Prevent warning if -Wstrict-prototypes.  */
#ifdef __GNUC__
int yyparse (void);
#endif

#if __GNUC__ > 1		/* GNU C and GNU C++ define this.  */
#define __yy_memcpy(TO,FROM,COUNT)	__builtin_memcpy(TO,FROM,COUNT)
#else				/* not GNU C or C++ */
#ifndef __cplusplus

/* This is the most reliable way to avoid incompatibilities
   in available built-in functions on various systems.  */
static void
__yy_memcpy (to, from, count)
     char *to;
     char *from;
     int count;
{
  register char *f = from;
  register char *t = to;
  register int i = count;

  while (i-- > 0)
    *t++ = *f++;
}

#else /* __cplusplus */

/* This is the most reliable way to avoid incompatibilities
   in available built-in functions on various systems.  */
static void
__yy_memcpy (char *to, char *from, int count)
{
  register char *f = from;
  register char *t = to;
  register int i = count;

  while (i-- > 0)
    *t++ = *f++;
}

#endif
#endif

#line 196 "/usr/lib/bison.simple"

/* The user can define YYPARSE_PARAM as the name of an argument to be passed
   into yyparse.  The argument should have type void *.
   It should actually point to an object.
   Grammar actions can access the variable by casting it
   to the proper pointer type.  */

#ifdef YYPARSE_PARAM
#ifdef __cplusplus
#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
#define YYPARSE_PARAM_DECL
#else /* not __cplusplus */
#define YYPARSE_PARAM_ARG YYPARSE_PARAM
#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
#endif /* not __cplusplus */
#else /* not YYPARSE_PARAM */
#define YYPARSE_PARAM_ARG
#define YYPARSE_PARAM_DECL
#endif /* not YYPARSE_PARAM */

int
yyparse(YYPARSE_PARAM_ARG)
     YYPARSE_PARAM_DECL
{
  register int yystate;
  register int yyn;
  register short *yyssp;
  register YYSTYPE *yyvsp;
  int yyerrstatus;	/*  number of tokens to shift before error messages enabled */
  int yychar1 = 0;		/*  lookahead token as an internal (translated) token number */

  short	yyssa[YYINITDEPTH];	/*  the state stack			*/
  YYSTYPE yyvsa[YYINITDEPTH];	/*  the semantic value stack		*/

  short *yyss = yyssa;		/*  refer to the stacks thru separate pointers */
  YYSTYPE *yyvs = yyvsa;	/*  to allow yyoverflow to reallocate them elsewhere */

#ifdef YYLSP_NEEDED
  YYLTYPE yylsa[YYINITDEPTH];	/*  the location stack			*/
  YYLTYPE *yyls = yylsa;
  YYLTYPE *yylsp;

#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
#else
#define YYPOPSTACK   (yyvsp--, yyssp--)
#endif

  int yystacksize = YYINITDEPTH;

#ifdef YYPURE
  int yychar;
  YYSTYPE yylval;
  int yynerrs;
#ifdef YYLSP_NEEDED
  YYLTYPE yylloc;
#endif
#endif

  YYSTYPE yyval;		/*  the variable used to return		*/
				/*  semantic values from the action	*/
				/*  routines				*/

  int yylen;

#if YYDEBUG != 0
  if (yydebug)
    fprintf(stderr, "Starting parse\n");
#endif

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY;		/* Cause a token to be read.  */

  /* Initialize stack pointers.
     Waste one element of value and location stack
     so that they stay on the same level as the state stack.
     The wasted elements are never initialized.  */

  yyssp = yyss - 1;
  yyvsp = yyvs;
#ifdef YYLSP_NEEDED
  yylsp = yyls;
#endif

/* Push a new state, which is found in  yystate  .  */
/* In all cases, when you get here, the value and location stacks
   have just been pushed. so pushing a state here evens the stacks.  */
yynewstate:

  *++yyssp = yystate;

  if (yyssp >= yyss + yystacksize - 1)
    {
      /* Give user a chance to reallocate the stack */
      /* Use copies of these so that the &'s don't force the real ones into memory. */
      YYSTYPE *yyvs1 = yyvs;
      short *yyss1 = yyss;
#ifdef YYLSP_NEEDED
      YYLTYPE *yyls1 = yyls;
#endif

      /* Get the current used size of the three stacks, in elements.  */
      int size = yyssp - yyss + 1;

#ifdef yyoverflow
      /* Each stack pointer address is followed by the size of
	 the data in use in that stack, in bytes.  */
#ifdef YYLSP_NEEDED
      /* This used to be a conditional around just the two extra args,
	 but that might be undefined if yyoverflow is a macro.  */
      yyoverflow("parser stack overflow",
		 &yyss1, size * sizeof (*yyssp),
		 &yyvs1, size * sizeof (*yyvsp),
		 &yyls1, size * sizeof (*yylsp),
		 &yystacksize);
#else
      yyoverflow("parser stack overflow",
		 &yyss1, size * sizeof (*yyssp),
		 &yyvs1, size * sizeof (*yyvsp),
		 &yystacksize);
#endif

      yyss = yyss1; yyvs = yyvs1;
#ifdef YYLSP_NEEDED
      yyls = yyls1;
#endif
#else /* no yyoverflow */
      /* Extend the stack our own way.  */
      if (yystacksize >= YYMAXDEPTH)
	{
	  yyerror("parser stack overflow");
	  return 2;
	}
      yystacksize *= 2;
      if (yystacksize > YYMAXDEPTH)
	yystacksize = YYMAXDEPTH;
      yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
      __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
      yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
      __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
#ifdef YYLSP_NEEDED
      yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
      __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
#endif
#endif /* no yyoverflow */

      yyssp = yyss + size - 1;
      yyvsp = yyvs + size - 1;
#ifdef YYLSP_NEEDED
      yylsp = yyls + size - 1;
#endif

#if YYDEBUG != 0
      if (yydebug)
	fprintf(stderr, "Stack size increased to %d\n", yystacksize);
#endif

      if (yyssp >= yyss + yystacksize - 1)
	YYABORT;
    }

#if YYDEBUG != 0
  if (yydebug)
    fprintf(stderr, "Entering state %d\n", yystate);
#endif

  goto yybackup;
 yybackup:

/* Do appropriate processing given the current state.  */
/* Read a lookahead token if we need one and don't already have one.  */
/* yyresume: */

  /* First try to decide what to do without reference to lookahead token.  */

  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* yychar is either YYEMPTY or YYEOF
     or a valid token in external form.  */

  if (yychar == YYEMPTY)
    {
#if YYDEBUG != 0
      if (yydebug)
	fprintf(stderr, "Reading a token: ");
#endif
      yychar = YYLEX;
    }

  /* Convert token to internal form (in yychar1) for indexing tables with */

  if (yychar <= 0)		/* This means end of input. */
    {
      yychar1 = 0;
      yychar = YYEOF;		/* Don't call YYLEX any more */

#if YYDEBUG != 0
      if (yydebug)
	fprintf(stderr, "Now at end of input.\n");
#endif
    }
  else
    {
      yychar1 = YYTRANSLATE(yychar);

#if YYDEBUG != 0
      if (yydebug)
	{
	  fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
	  /* Give the individual parser a way to print the precise meaning
	     of a token, for further debugging info.  */
#ifdef YYPRINT
	  YYPRINT (stderr, yychar, yylval);
#endif
	  fprintf (stderr, ")\n");
	}
#endif
    }

  yyn += yychar1;
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
    goto yydefault;

  yyn = yytable[yyn];

  /* yyn is what to do for this token type in this state.
     Negative => reduce, -yyn is rule number.
     Positive => shift, yyn is new state.
       New state is final state => don't bother to shift,
       just return success.
     0, or most negative number => error.  */

  if (yyn < 0)
    {
      if (yyn == YYFLAG)
	goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  else if (yyn == 0)
    goto yyerrlab;

  if (yyn == YYFINAL)
    YYACCEPT;

  /* Shift the lookahead token.  */

#if YYDEBUG != 0
  if (yydebug)
    fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
#endif

  /* Discard the token being shifted unless it is eof.  */
  if (yychar != YYEOF)
    yychar = YYEMPTY;

  *++yyvsp = yylval;
#ifdef YYLSP_NEEDED
  *++yylsp = yylloc;
#endif

  /* count tokens shifted since error; after three, turn off error status.  */
  if (yyerrstatus) yyerrstatus--;

  yystate = yyn;
  goto yynewstate;

/* Do the default action for the current state.  */
yydefault:

  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;

/* Do a reduction.  yyn is the number of a rule to reduce with.  */
yyreduce:
  yylen = yyr2[yyn];
  if (yylen > 0)
    yyval = yyvsp[1-yylen]; /* implement default value of the action */

#if YYDEBUG != 0
  if (yydebug)
    {
      int i;

      fprintf (stderr, "Reducing via rule %d (line %d), ",
	       yyn, yyrline[yyn]);

      /* Print the symbols being reduced, and their result.  */
      for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
	fprintf (stderr, "%s ", yytname[yyrhs[i]]);
      fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
    }
#endif


  switch (yyn) {

case 1:
#line 208 "parse.y"
{ yyval.prog=theProg=NOPROG; ;
    break;}
case 2:
#line 210 "parse.y"
{ yyval.prog=theProg=yyvsp[0].prog; ;
    break;}
case 3:
#line 213 "parse.y"
{ yyval.prog=yyvsp[0].prog; ;
    break;}
case 4:
#line 215 "parse.y"
{ yyval.prog=yyvsp[0].prog; ;
    break;}
case 5:
#line 217 "parse.y"
{ yyval.prog=yyvsp[-1].prog; ;
    break;}
case 6:
#line 219 "parse.y"
{ yyval.prog = (yyvsp[-1].prog==NOPROG) ? yyvsp[0].prog : New2Op( I_SEQ, yyvsp[-1].prog, yyvsp[0].prog ); ;
    break;}
case 7:
#line 222 "parse.y"
{ if (yyvsp[-1].prog!=NOPROG) EvalDefault(yyvsp[-1].prog); yyval.prog=NOPROG; ;
    break;}
case 8:
#line 225 "parse.y"
{ yyval.prog=yyvsp[0].prog; ;
    break;}
case 9:
#line 227 "parse.y"
{ yyval.prog = (yyvsp[-1].prog==NOPROG) ? yyvsp[0].prog : New2Op( I_SEQ, yyvsp[-1].prog, yyvsp[0].prog ); ;
    break;}
case 10:
#line 230 "parse.y"
{ yyval.prog=NOPROG; ;
    break;}
case 11:
#line 232 "parse.y"
{ yyval.prog=yyvsp[-1].prog; ;
    break;}
case 12:
#line 235 "parse.y"
{ yyval.prog=yyvsp[0].prog; ;
    break;}
case 13:
#line 237 "parse.y"
{ yyval.prog=New2Op( I_SEQ, yyvsp[-1].prog, yyvsp[0].prog ); ;
    break;}
case 14:
#line 240 "parse.y"
{ yyval.prog=yyvsp[-1].prog; ;
    break;}
case 15:
#line 242 "parse.y"
{ yyval.prog=yyvsp[-1].prog; ;
    break;}
case 16:
#line 244 "parse.y"
{ yyval.prog=New3Op( I_COND, yyvsp[-1].prog, yyvsp[0].prog, NOPROG ); ;
    break;}
case 17:
#line 246 "parse.y"
{ yyval.prog=New3Op( I_COND, yyvsp[-3].prog, yyvsp[-2].prog, yyvsp[0].prog ); ;
    break;}
case 18:
#line 249 "parse.y"
{ yyval.prog=yyvsp[0].prog; ;
    break;}
case 19:
#line 251 "parse.y"
{ yyval.prog=New2Op( I_AND, yyvsp[-2].prog, yyvsp[0].prog ); ;
    break;}
case 20:
#line 253 "parse.y"
{ yyval.prog=New2Op( I_OR, yyvsp[-2].prog, yyvsp[0].prog ); ;
    break;}
case 21:
#line 256 "parse.y"
{ yyval.prog=yyvsp[0].prog; ;
    break;}
case 22:
#line 258 "parse.y"
{ yyval.prog=New1Op( I_NOT, yyvsp[0].prog ); ;
    break;}
case 23:
#line 260 "parse.y"
{ yyval.prog=yyvsp[-1].prog; ;
    break;}
case 24:
#line 263 "parse.y"
{ yyval.prog=NewOwnerOp( yyvsp[0].string, I_OWNER, yyvsp[-2].string ); ;
    break;}
case 25:
#line 265 "parse.y"
{ yyval.prog=NewGroupOp( yyvsp[0].string, I_GROUP, yyvsp[-2].string ); ;
    break;}
case 26:
#line 267 "parse.y"
{ yyval.prog=NewFileOp( yyvsp[0].string, I_FILE ); ;
    break;}
case 27:
#line 269 "parse.y"
{ yyval.prog=NewFileOp( yyvsp[0].string, I_PATH ); ;
    break;}
case 28:
#line 271 "parse.y"
{ yyval.prog=NewTypeOp( yyvsp[0].string, yyvsp[-2].string ); ;
    break;}
case 29:
#line 273 "parse.y"
{ yyval.prog=NewPermOp( yyvsp[0].string, I_MODE, yyvsp[-2].string ); ;
    break;}
case 30:
#line 275 "parse.y"
{ yyval.prog=NewAgeOp( yyvsp[0].string, 1, I_AGE, yyvsp[-2].string ); ;
    break;}
case 31:
#line 277 "parse.y"
{ yyval.prog=NewAgeOp( yyvsp[0].string, 0, I_AGE, yyvsp[-2].string ); ;
    break;}
case 32:
#line 279 "parse.y"
{ yyval.prog=NewAgeOp( yyvsp[0].string, -1, I_AGE, yyvsp[-2].string ); ;
    break;}
case 33:
#line 281 "parse.y"
{ yyval.prog=NewAgeOp( NOSTR, 1, I_AGE, yyvsp[0].string ); ;
    break;}
case 34:
#line 283 "parse.y"
{ yyval.prog=NewAgeOp( yyvsp[0].string, 1, I_ACCESS, yyvsp[-2].string ); ;
    break;}
case 35:
#line 285 "parse.y"
{ yyval.prog=NewAgeOp( yyvsp[0].string, 0, I_ACCESS, yyvsp[-2].string ); ;
    break;}
case 36:
#line 287 "parse.y"
{ yyval.prog=NewAgeOp( yyvsp[0].string, -1, I_ACCESS, yyvsp[-2].string ); ;
    break;}
case 37:
#line 289 "parse.y"
{ yyval.prog=NewSizeOp( yyvsp[0].string, 1, yyvsp[-2].string ); ;
    break;}
case 38:
#line 291 "parse.y"
{ yyval.prog=NewSizeOp( yyvsp[0].string, 0, yyvsp[-2].string ); ;
    break;}
case 39:
#line 293 "parse.y"
{ yyval.prog=NewSizeOp( yyvsp[0].string, -1, yyvsp[-2].string ); ;
    break;}
case 40:
#line 295 "parse.y"
{ yyval.prog=New1Op( I_NOT, NewOwnerOp( yyvsp[0].string, I_OWNER, yyvsp[-2].string ) );;
    break;}
case 41:
#line 297 "parse.y"
{ yyval.prog=New1Op( I_NOT, NewGroupOp( yyvsp[0].string, I_GROUP, yyvsp[-2].string ) );;
    break;}
case 42:
#line 299 "parse.y"
{ yyval.prog=New1Op( I_NOT, NewFileOp( yyvsp[0].string, I_FILE ) ); ;
    break;}
case 43:
#line 301 "parse.y"
{ yyval.prog=New1Op( I_NOT, NewFileOp( yyvsp[0].string, I_PATH ) ); ;
    break;}
case 44:
#line 303 "parse.y"
{ yyval.prog=New1Op( I_NOT, NewTypeOp( yyvsp[0].string, yyvsp[-2].string ) ); ;
    break;}
case 45:
#line 305 "parse.y"
{ yyval.prog=New1Op( I_NOT, NewTypeOp( "missing", yyvsp[0].string ) ); ;
    break;}
case 46:
#line 307 "parse.y"
{ yyval.prog=New1Op( I_NOT, NewPermOp( yyvsp[0].string, I_MODE, yyvsp[-2].string ) ); ;
    break;}
case 47:
#line 310 "parse.y"
{ yyval.string=NULL; ;
    break;}
case 48:
#line 312 "parse.y"
{ yyval.string=yyvsp[-1].string; ;
    break;}
case 49:
#line 314 "parse.y"
{ yyval.string=NewString(yyvsp[-1].string,"=",yyvsp[-3].string,NOSTR); yyval.string[strlen(yyvsp[-1].string)]='\0'; ;
    break;}
case 50:
#line 317 "parse.y"
{ optm = true; ;
    break;}
case 51:
#line 319 "parse.y"
{
#ifdef LFU_CACHE
                    CacheOption( T_CACHEFILE, yyvsp[0].string );
#endif
                  ;
    break;}
case 52:
#line 325 "parse.y"
{
#ifdef LFU_CACHE
                    CacheOption( T_CACHEMINSIZE, yyvsp[0].string );
#endif
                  ;
    break;}
case 53:
#line 331 "parse.y"
{
#ifdef LFU_CACHE
                    CacheOption( T_CACHEMINFREE, yyvsp[0].string );
#endif
                  ;
    break;}
case 54:
#line 337 "parse.y"
{
#ifdef LFU_CACHE
                    CacheOption( T_CACHEMINVALUE, yyvsp[0].string );
#endif
                  ;
    break;}
case 55:
#line 343 "parse.y"
{
#ifdef LFU_CACHE
                    CacheOption( T_CACHEFILL, NOSTR );
#endif
                  ;
    break;}
case 56:
#line 349 "parse.y"
{ StartString(); ;
    break;}
case 57:
#line 350 "parse.y"
{ EndString(); yyval.string=yyvsp[0].string; ;
    break;}
case 58:
#line 353 "parse.y"
{ yyval.string=yyvsp[0].string; ;
    break;}
case 59:
#line 355 "parse.y"
{ yyval.string=NewString( yyvsp[-1].string, " ", yyvsp[0].string, NULL ); free(yyvsp[-1].string); free(yyvsp[0].string); ;
    break;}
case 60:
#line 358 "parse.y"
{ yyval.prog=NewFTypeOp( I_TYPE, A_UPDATE ); ;
    break;}
case 61:
#line 360 "parse.y"
{ yyval.prog=NewFTypeOp( I_TYPE, A_PRESERVE ); ;
    break;}
case 62:
#line 362 "parse.y"
{ yyval.prog=NewFTypeOp( I_TYPE, A_DELETE ); ;
    break;}
case 63:
#line 364 "parse.y"
{ yyval.prog=NewFTypeOp( I_TYPE, A_IGNORE ); ;
    break;}
case 64:
#line 366 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_LNK ); ;
    break;}
case 65:
#line 368 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_LNK ); ;
    break;}
case 66:
#line 370 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_SHADOW ); ;
    break;}
case 67:
#line 372 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_SHADOW ); ;
    break;}
case 68:
#line 374 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_NEWTIME ); ;
    break;}
case 69:
#line 376 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_NEWTIME ); ;
    break;}
case 70:
#line 378 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_KEEP ); ;
    break;}
case 71:
#line 380 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_KEEP ); ;
    break;}
case 72:
#line 382 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_LOG ); ;
    break;}
case 73:
#line 384 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_LOG ); ;
    break;}
case 74:
#line 386 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_LOGALL|F_LOG ); ;
    break;}
case 75:
#line 388 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_LOGALL|F_LOG ); ;
    break;}
case 76:
#line 390 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_NOIDCHECK ); ;
    break;}
case 77:
#line 392 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_NOIDCHECK ); ;
    break;}
case 78:
#line 394 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_FORCE ); ;
    break;}
case 79:
#line 396 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_FORCE ); ;
    break;}
case 80:
#line 398 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_FILL ); ;
    break;}
case 81:
#line 400 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_FILL ); ;
    break;}
case 82:
#line 402 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_NOINHERIT ); ;
    break;}
case 83:
#line 404 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_NOINHERIT ); ;
    break;}
case 84:
#line 406 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_CDF ); ;
    break;}
case 85:
#line 408 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_CDF ); ;
    break;}
case 86:
#line 410 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_STATS ); ;
    break;}
case 87:
#line 412 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_STATS ); ;
    break;}
case 88:
#line 414 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_NEWER ); ;
    break;}
case 89:
#line 416 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_NEWER ); ;
    break;}
case 90:
#line 418 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_FOLLOW ); ;
    break;}
case 91:
#line 420 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_FOLLOW ); ;
    break;}
case 92:
#line 422 "parse.y"
{ yyval.prog=NewIntOp( I_SET, F_COMPRESS ); ;
    break;}
case 93:
#line 424 "parse.y"
{ yyval.prog=NewIntOp( I_CLR, F_COMPRESS ); ;
    break;}
case 94:
#line 426 "parse.y"
{ yyval.prog=NewPermOp( yyvsp[0].string, I_PSET, NOSTR ); ;
    break;}
case 95:
#line 428 "parse.y"
{ yyval.prog=NewPermOp( NOSTR, I_PSET, NOSTR ); ;
    break;}
case 96:
#line 430 "parse.y"
{ yyval.prog=NewStringOp( I_EXEC, yyvsp[0].string, NOSTR ); ;
    break;}
case 97:
#line 432 "parse.y"
{ yyval.prog=NewStringOp( I_EXEC, NOSTR, NOSTR ); ;
    break;}
case 98:
#line 434 "parse.y"
{ yyval.prog=NewAutoOp( yyvsp[0].string ); ;
    break;}
case 99:
#line 436 "parse.y"
{ yyval.prog=NewAutoOp( NOSTR ); ;
    break;}
case 100:
#line 438 "parse.y"
{ yyval.prog=NewStringOp( I_ERROR, yyvsp[0].string, NOSTR ); ;
    break;}
case 101:
#line 440 "parse.y"
{ yyval.prog=NewStringOp( I_ERROR, NOSTR, NOSTR ); ;
    break;}
case 102:
#line 442 "parse.y"
{ yyval.prog=NewStringOp( I_WARN, yyvsp[0].string, NOSTR ); ;
    break;}
case 103:
#line 444 "parse.y"
{ yyval.prog=NewStringOp( I_WARN, NOSTR, NOSTR ); ;
    break;}
case 104:
#line 446 "parse.y"
{ yyval.prog=NewStringOp( I_SRC, yyvsp[0].string, NOSTR ); ;
    break;}
case 105:
#line 448 "parse.y"
{ yyval.prog=NewStringOp( I_SRC, yyvsp[0].string, yyvsp[-2].string ); ;
    break;}
case 106:
#line 450 "parse.y"
{ yyval.prog=NewStringOp( I_SRC, NOSTR, NOSTR ); ;
    break;}
case 107:
#line 452 "parse.y"
{ yyval.prog=NewOwnerOp( yyvsp[0].string, I_CHOWN, NOSTR ); ;
    break;}
case 108:
#line 454 "parse.y"
{ yyval.prog=NewOwnerOp( NOSTR, I_CHOWN, NOSTR ); ;
    break;}
case 109:
#line 456 "parse.y"
{ yyval.prog=NewGroupOp( yyvsp[0].string, I_CHGRP, NOSTR ); ;
    break;}
case 110:
#line 458 "parse.y"
{ yyval.prog=NewGroupOp( NOSTR, I_CHGRP, NOSTR ); ;
    break;}
case 111:
#line 460 "parse.y"
{ 
#ifdef LFU_CACHE
		    yyval.prog=NewCacheOp( yyvsp[0].string );
#endif
                  ;
    break;}
case 112:
#line 466 "parse.y"
{ 
#ifdef LFU_CACHE
		    yyval.prog=NewCacheOp( "0" );
#endif
                  ;
    break;}
case 113:
#line 472 "parse.y"
{
#ifdef LFU_CACHE
		    yyval.prog=NewCacheOp( NOSTR );
#endif
                  ;
    break;}
}
   /* the action file gets copied in in place of this dollarsign */
#line 498 "/usr/lib/bison.simple"

  yyvsp -= yylen;
  yyssp -= yylen;
#ifdef YYLSP_NEEDED
  yylsp -= yylen;
#endif

#if YYDEBUG != 0
  if (yydebug)
    {
      short *ssp1 = yyss - 1;
      fprintf (stderr, "state stack now");
      while (ssp1 != yyssp)
	fprintf (stderr, " %d", *++ssp1);
      fprintf (stderr, "\n");
    }
#endif

  *++yyvsp = yyval;

#ifdef YYLSP_NEEDED
  yylsp++;
  if (yylen == 0)
    {
      yylsp->first_line = yylloc.first_line;
      yylsp->first_column = yylloc.first_column;
      yylsp->last_line = (yylsp-1)->last_line;
      yylsp->last_column = (yylsp-1)->last_column;
      yylsp->text = 0;
    }
  else
    {
      yylsp->last_line = (yylsp+yylen-1)->last_line;
      yylsp->last_column = (yylsp+yylen-1)->last_column;
    }
#endif

  /* Now "shift" the result of the reduction.
     Determine what state that goes to,
     based on the state we popped back to
     and the rule number reduced by.  */

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTBASE];

  goto yynewstate;

yyerrlab:   /* here on detecting error */

  if (! yyerrstatus)
    /* If not already recovering from an error, report this error.  */
    {
      ++yynerrs;

#ifdef YYERROR_VERBOSE
      yyn = yypact[yystate];

      if (yyn > YYFLAG && yyn < YYLAST)
	{
	  int size = 0;
	  char *msg;
	  int x, count;

	  count = 0;
	  /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
	  for (x = (yyn < 0 ? -yyn : 0);
	       x < (sizeof(yytname) / sizeof(char *)); x++)
	    if (yycheck[x + yyn] == x)
	      size += strlen(yytname[x]) + 15, count++;
	  msg = (char *) malloc(size + 15);
	  if (msg != 0)
	    {
	      strcpy(msg, "parse error");

	      if (count < 5)
		{
		  count = 0;
		  for (x = (yyn < 0 ? -yyn : 0);
		       x < (sizeof(yytname) / sizeof(char *)); x++)
		    if (yycheck[x + yyn] == x)
		      {
			strcat(msg, count == 0 ? ", expecting `" : " or `");
			strcat(msg, yytname[x]);
			strcat(msg, "'");
			count++;
		      }
		}
	      yyerror(msg);
	      free(msg);
	    }
	  else
	    yyerror ("parse error; also virtual memory exceeded");
	}
      else
#endif /* YYERROR_VERBOSE */
	yyerror("parse error");
    }

  goto yyerrlab1;
yyerrlab1:   /* here on error raised explicitly by an action */

  if (yyerrstatus == 3)
    {
      /* if just tried and failed to reuse lookahead token after an error, discard it.  */

      /* return failure if at end of input */
      if (yychar == YYEOF)
	YYABORT;

#if YYDEBUG != 0
      if (yydebug)
	fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
#endif

      yychar = YYEMPTY;
    }

  /* Else will try to reuse lookahead token
     after shifting the error token.  */

  yyerrstatus = 3;		/* Each real token shifted decrements this */

  goto yyerrhandle;

yyerrdefault:  /* current state does not do anything special for the error token. */

#if 0
  /* This is wrong; only states that explicitly want error tokens
     should shift them.  */
  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  if (yyn) goto yydefault;
#endif

yyerrpop:   /* pop the current state because it cannot handle the error token */

  if (yyssp == yyss) YYABORT;
  yyvsp--;
  yystate = *--yyssp;
#ifdef YYLSP_NEEDED
  yylsp--;
#endif

#if YYDEBUG != 0
  if (yydebug)
    {
      short *ssp1 = yyss - 1;
      fprintf (stderr, "Error: state stack now");
      while (ssp1 != yyssp)
	fprintf (stderr, " %d", *++ssp1);
      fprintf (stderr, "\n");
    }
#endif

yyerrhandle:

  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    goto yyerrdefault;

  yyn += YYTERROR;
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
    goto yyerrdefault;

  yyn = yytable[yyn];
  if (yyn < 0)
    {
      if (yyn == YYFLAG)
	goto yyerrpop;
      yyn = -yyn;
      goto yyreduce;
    }
  else if (yyn == 0)
    goto yyerrpop;

  if (yyn == YYFINAL)
    YYACCEPT;

#if YYDEBUG != 0
  if (yydebug)
    fprintf(stderr, "Shifting error token, ");
#endif

  *++yyvsp = yylval;
#ifdef YYLSP_NEEDED
  *++yylsp = yylloc;
#endif

  yystate = yyn;
  goto yynewstate;
}
#line 477 "parse.y"


/*************************************************************************/
  PROG ParseFile( cp, fname )
/*************************************************************************/
PROG cp;
char *fname;
{
#ifdef YYDEBUG
  yydebug=1;
#endif
  ScanFile(fname);
  (void)yyparse();
  EndScan();
  return (cp) ? New2Op( I_SEQ, cp, theProg ) : theProg;
}

/*************************************************************************/
  PROG ParseString( cp, s )
/*************************************************************************/
PROG cp;
char *s;
{
#ifdef YYDEBUG
  yydebug=1;
#endif
  ScanString(s);
  (void)yyparse();
  EndScan();
  return (cp) ? New2Op( I_SEQ, cp, theProg ) : theProg;
}

/*************************************************************************/
  int yywrap()
/*************************************************************************/
{
  return 1;
}

#ifdef HAVE_VERBOSE_PARSER_MSGS

/*************************************************************************/
  int VerboseErr(yystate, s)
/*************************************************************************/
int yystate;
char *s;
{
  /* This routine depends on the internals of the code generated by Bison.
     It is similar to the Bison option YYERROR_VERBOSE, except that it
     does some additional work to print class names rather than individual
     tokens */

  AVL_TREE msgTree;
  char *msg;
  int yyn, i;

  if ((msgTree=AVL_NewTree(AVL_StrCmp)) == NULL) Fatal(E_MEM, NOSTR, NOSTR);

  yyn = yypact[yystate];
  msg = NewString( s, NULL );

  if (yyn>YYFLAG && yyn<YYLAST) {

    for (i=0; i<(sizeof(yytname) / sizeof(char *)); ++i) {
      if (yycheck[i+yyn] == i) {
	AVL_KEY k;
	AVL_VALUE v;
	if (yytname[i]==NOSTR) continue;
	k.s = yytname[i];
	v.s = NOSTR;
	if (AVL_Add(k, v, msgTree) == NULL) Fatal(E_MEM, NOSTR, NOSTR);
      }
    }

    for (i=0; AVL_Size(msgTree)>0; ++i) {
      AVL_NODE np=AVL_First(msgTree);
      char *newMsg = (i==0) ?
	NewString( msg, ": expecting ", AVL_Key(np).s, NULL ) :
	  NewString( msg, " or ", AVL_Key(np).s, NULL );
      free(msg);
      msg = newMsg;
      AVL_Remove( AVL_Key(np), msgTree );
    }
  }

  if (theFile) {
    Fatal( E_FPARSE, msg, FilePos(theFile, lineNo, 1+colNo) );
  } else {
    while (lineNo>1) {
      while (*theString!='\0' && *theString!='\n') ++theString;
      if (*theString=='\n') ++theString;
      --lineNo;
    }
    for (s=theString; *s!='\0'; ++s) {
      if (*s=='\n') { *s='\0'; break; }
    }
    s = (char*)NewMem(10+strlen(theString));
    strncpy(s, theString, colNo);
    s[colNo] = '\0';
    strcat(s, "<HERE>");
    strcat(s, theString+colNo);
    Fatal( E_SPARSE, msg, s );
  }
}

#else

/*************************************************************************/
  int yyerror(s)
/*************************************************************************/
char *s;
{
  if (theFile) {
    Fatal( E_FPARSE, s, FilePos(theFile, lineNo, colNo) );
  } else Fatal( E_SPARSE, s, theString );

  /*NOTREACHED*/ return 0;
}

#endif
lfu-3.1.5/src/scan.c   644  75362  74430      146066  6510207107   7440 /* A lexical scanner generated by flex */

/* Scanner skeleton version:
 * $Header: /a/staffa/disk/home/src4/ladm/lfu/lfu-3/src/RCS/scan.c,v 1.4 1998/03/31 15:39:07 paul Exp paul $
 */

#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5

#include <stdio.h>


/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
#ifdef c_plusplus
#ifndef __cplusplus
#define __cplusplus
#endif
#endif


#ifdef __cplusplus

#include <stdlib.h>
#include <unistd.h>

/* Use prototypes in function declarations. */
#define YY_USE_PROTOS

/* The "const" storage-class-modifier is valid. */
#define YY_USE_CONST

#else	/* ! __cplusplus */

#if __STDC__

#define YY_USE_PROTOS
#define YY_USE_CONST

#endif	/* __STDC__ */
#endif	/* ! __cplusplus */

#ifdef __TURBOC__
 #pragma warn -rch
 #pragma warn -use
#include <io.h>
#include <stdlib.h>
#define YY_USE_CONST
#define YY_USE_PROTOS
#endif

#ifdef YY_USE_CONST
#define yyconst const
#else
#define yyconst
#endif


#ifdef YY_USE_PROTOS
#define YY_PROTO(proto) proto
#else
#define YY_PROTO(proto) ()
#endif

/* Returned upon end-of-file. */
#define YY_NULL 0

/* Promotes a possibly negative, possibly signed char to an unsigned
 * integer for use as an array index.  If the signed char is negative,
 * we want to instead treat it as an 8-bit unsigned char, hence the
 * double cast.
 */
#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)

/* Enter a start condition.  This macro really ought to take a parameter,
 * but we do it the disgusting crufty way forced on us by the ()-less
 * definition of BEGIN.
 */
#define BEGIN yy_start = 1 + 2 *

/* Translate the current start state into a value that can be later handed
 * to BEGIN to return to the state.  The YYSTATE alias is for lex
 * compatibility.
 */
#define YY_START ((yy_start - 1) / 2)
#define YYSTATE YY_START

/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)

/* Special action meaning "start processing a new file". */
#define YY_NEW_FILE yyrestart( yyin )

#define YY_END_OF_BUFFER_CHAR 0

/* Size of default input buffer. */
#define YY_BUF_SIZE 16384

typedef struct yy_buffer_state *YY_BUFFER_STATE;

extern int yyleng;
extern FILE *yyin, *yyout;

#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2

/* The funky do-while in the following #define is used to turn the definition
 * int a single C statement (which needs a semi-colon terminator).  This
 * avoids problems with code like:
 *
 * 	if ( condition_holds )
 *		yyless( 5 );
 *	else
 *		do_something_else();
 *
 * Prior to using the do-while the compiler would get upset at the
 * "else" because it interpreted the "if" statement as being all
 * done when it reached the ';' after the yyless() call.
 */

/* Return all but the first 'n' matched characters back to the input stream. */

#define yyless(n) \
	do \
		{ \
		/* Undo effects of setting up yytext. */ \
		*yy_cp = yy_hold_char; \
		YY_RESTORE_YY_MORE_OFFSET \
		yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
		} \
	while ( 0 )

#define unput(c) yyunput( c, yytext_ptr )

/* The following is because we cannot portably get our hands on size_t
 * (without autoconf's help, which isn't available because we want
 * flex-generated scanners to compile on their own).
 */
typedef unsigned int yy_size_t;


struct yy_buffer_state
	{
	FILE *yy_input_file;

	char *yy_ch_buf;		/* input buffer */
	char *yy_buf_pos;		/* current position in input buffer */

	/* Size of input buffer in bytes, not including room for EOB
	 * characters.
	 */
	yy_size_t yy_buf_size;

	/* Number of characters read into yy_ch_buf, not including EOB
	 * characters.
	 */
	int yy_n_chars;

	/* Whether we "own" the buffer - i.e., we know we created it,
	 * and can realloc() it to grow it, and should free() it to
	 * delete it.
	 */
	int yy_is_our_buffer;

	/* Whether this is an "interactive" input source; if so, and
	 * if we're using stdio for input, then we want to use getc()
	 * instead of fread(), to make sure we stop fetching input after
	 * each newline.
	 */
	int yy_is_interactive;

	/* Whether we're considered to be at the beginning of a line.
	 * If so, '^' rules will be active on the next match, otherwise
	 * not.
	 */
	int yy_at_bol;

	/* Whether to try to fill the input buffer when we reach the
	 * end of it.
	 */
	int yy_fill_buffer;

	int yy_buffer_status;
#define YY_BUFFER_NEW 0
#define YY_BUFFER_NORMAL 1
	/* When an EOF's been seen but there's still some text to process
	 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
	 * shouldn't try reading from the input source any more.  We might
	 * still have a bunch of tokens to match, though, because of
	 * possible backing-up.
	 *
	 * When we actually see the EOF, we change the status to "new"
	 * (via yyrestart()), so that the user can continue scanning by
	 * just pointing yyin at a new input file.
	 */
#define YY_BUFFER_EOF_PENDING 2
	};

static YY_BUFFER_STATE yy_current_buffer = 0;

/* We provide macros for accessing buffer states in case in the
 * future we want to put the buffer states in a more general
 * "scanner state".
 */
#define YY_CURRENT_BUFFER yy_current_buffer


/* yy_hold_char holds the character lost when yytext is formed. */
static char yy_hold_char;

static int yy_n_chars;		/* number of characters read into yy_ch_buf */


int yyleng;

/* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0;
static int yy_init = 1;		/* whether we need to initialize */
static int yy_start = 0;	/* start state number */

/* Flag which is used to allow yywrap()'s to do buffer switches
 * instead of setting up a fresh yyin.  A bit of a hack ...
 */
static int yy_did_buffer_switch_on_eof;

void yyrestart YY_PROTO(( FILE *input_file ));

void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
void yy_load_buffer_state YY_PROTO(( void ));
YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )

YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));

static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
static void yy_flex_free YY_PROTO(( void * ));

#define yy_new_buffer yy_create_buffer

#define yy_set_interactive(is_interactive) \
	{ \
	if ( ! yy_current_buffer ) \
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
	yy_current_buffer->yy_is_interactive = is_interactive; \
	}

#define yy_set_bol(at_bol) \
	{ \
	if ( ! yy_current_buffer ) \
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
	yy_current_buffer->yy_at_bol = at_bol; \
	}

#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)

typedef unsigned char YY_CHAR;
FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
typedef int yy_state_type;
extern char *yytext;
#define yytext_ptr yytext

static yy_state_type yy_get_previous_state YY_PROTO(( void ));
static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
static int yy_get_next_buffer YY_PROTO(( void ));
static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));

/* Done after the current pattern has been matched and before the
 * corresponding action - sets up yytext.
 */
#define YY_DO_BEFORE_ACTION \
	yytext_ptr = yy_bp; \
	yyleng = (int) (yy_cp - yy_bp); \
	yy_hold_char = *yy_cp; \
	*yy_cp = '\0'; \
	yy_c_buf_p = yy_cp;

#define YY_NUM_RULES 31
#define YY_END_OF_BUFFER 32
static yyconst short int yy_accept[51] =
    {   0,
        0,    0,    0,    0,    0,    0,    0,    0,   32,   31,
        2,    2,   22,    5,    3,    4,   18,   23,   10,   12,
       13,    7,   21,   16,   20,   14,   15,    8,   11,    9,
       19,   22,   24,   30,   29,   31,    0,    1,   22,    4,
       17,   22,    0,    6,   24,   28,   27,   25,   26,    0
    } ;

static yyconst int yy_ec[256] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    4,    5,    6,    7,    1,    1,    8,    1,    9,
       10,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,   11,   12,
       13,   14,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
       15,   16,   17,    1,    1,    1,    1,    1,    1,    1,

        1,    1,    1,    1,    1,    1,    1,    1,    1,   18,
        1,    1,    1,    1,    1,   19,    1,    1,    1,    1,
        1,    1,   20,   21,   22,   23,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,

        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1
    } ;

static yyconst int yy_meta[24] =
    {   0,
        1,    2,    3,    2,    2,    3,    1,    2,    2,    2,
        2,    2,    2,    2,    2,    4,    2,    1,    1,    2,
        2,    2,    2
    } ;

static yyconst short int yy_base[59] =
    {   0,
        0,    0,   35,   33,    0,   29,   21,   22,   35,  107,
      107,   31,    0,  107,  107,   29,   19,  107,  107,  107,
      107,  107,  107,  107,  107,  107,  107,  107,  107,  107,
      107,   38,    0,  107,  107,   28,   27,  107,    0,   25,
      107,   57,   23,  107,    0,  107,  107,  107,  107,  107,
       76,   80,   84,   88,   92,   96,  100,  102
    } ;

static yyconst short int yy_def[59] =
    {   0,
       51,   51,   52,   52,   50,    5,   53,   53,   50,   50,
       50,   54,   55,   50,   50,   50,   50,   50,   50,   50,
       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
       50,   56,   57,   50,   50,   58,   54,   50,   55,   50,
       50,   56,   56,   50,   57,   50,   50,   50,   50,    0,
       50,   50,   50,   50,   50,   50,   50,   50
    } ;

static yyconst short int yy_nxt[131] =
    {   0,
       13,   14,   15,   16,   17,   18,   13,   19,   20,   21,
       22,   23,   24,   25,   26,   13,   27,   13,   13,   28,
       29,   30,   31,   34,   34,   44,   35,   35,   40,   38,
       47,   41,   40,   38,   50,   32,   36,   36,   42,   12,
       44,   12,   50,   50,   42,   48,   49,   50,   50,   50,
       50,   50,   50,   42,   50,   42,   42,   42,   50,   44,
       50,   50,   50,   42,   50,   50,   50,   50,   50,   50,
       50,   50,   42,   50,   42,   42,   10,   10,   10,   10,
       11,   11,   11,   11,   33,   33,   33,   33,   37,   37,
       37,   37,   39,   50,   50,   39,   43,   43,   43,   43,

       45,   45,   46,   46,   46,   46,    9,   50,   50,   50,
       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
       50,   50,   50,   50,   50,   50,   50,   50,   50,   50
    } ;

static yyconst short int yy_chk[131] =
    {   0,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    5,    5,    5,    5,    5,    5,    5,
        5,    5,    5,    7,    8,   43,    7,    8,   40,   37,
       36,   17,   16,   12,    9,    6,    7,    8,   32,    4,
       32,    3,    0,    0,   32,   36,   36,    0,    0,    0,
        0,    0,    0,   32,    0,   32,   32,   42,    0,   42,
        0,    0,    0,   42,    0,    0,    0,    0,    0,    0,
        0,    0,   42,    0,   42,   42,   51,   51,   51,   51,
       52,   52,   52,   52,   53,   53,   53,   53,   54,   54,
       54,   54,   55,    0,    0,   55,   56,   56,   56,   56,

       57,   57,   58,   58,   58,   58,   50,   50,   50,   50,
       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
       50,   50,   50,   50,   50,   50,   50,   50,   50,   50
    } ;

static yy_state_type yy_last_accepting_state;
static char *yy_last_accepting_cpos;

/* The intent behind this definition is that it'll catch
 * any uses of REJECT which flex missed.
 */
#define REJECT reject_used_but_not_detected
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "scan.l"
#define INITIAL 0
#line 2 "scan.l"
/**************************************************************************

  The program scanner.

  $Author: paul $
  $Revision: 1.4 $
  $Date: 1998/03/31 15:39:07 $

  Copyright (c) 1992 by the University of Edinburgh
  Laboratory for the Foundations of Computer Science
  Department of Computer Science
  Written by Paul Anderson.

  Permission is granted to anyone to use this software for any
  purpose on any computer system, and to redistribute it freely,
  subject to the following restrictions:

  The University of Edinburgh makes no representations about the
  suitability of this software for any purpose.  It is
  provided "as is" without express or implied warranty.

  The origin of this software must not be misrepresented, either by
  explicit claim or by omission, and this copyright notice must appear in
  all copies of the software. Altered versions must be plainly marked
  as such, and must not be misrepresented as being the original software.

  The name of the University of Edinburgh must not be used in
  advertising or publicity pertaining to distribution of the software
  without specific, written prior permission. 
 
**************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include "misc.h"
#include <sys/wait.h>
#include <string.h>
#include "tokens.h"

#define extern
#include "scan.h"
#undef extern

#ifdef LFU_DEBUG
#define Return(n) return(PrintToken(n))
#else
#define Return(n) return(n)
#endif

/**************************************************************************
  Macros & Constants
**************************************************************************/

#define TABSIZE 8

#define Col(n)  colNo=nextCol; nextCol+=(n)
#define Line(n) lineNo=nextLine; colNo=nextCol; nextLine+=(n); nextCol=0

/**************************************************************************
  I/O redirection
**************************************************************************/

#ifdef FLEX_SCANNER
#undef YY_INPUT
#define YY_INPUT(b,r,m) { int c=(*inp)(); r = c ?b[0]=c,1: YY_NULL; }
#else
#undef input
#define input()   ((*inp)())
#undef output
#define output(c) Output(c)
#undef unput
#define unput(c)  ((*unp)(c))
#endif

/**************************************************************************
  Globals
**************************************************************************/

extern YYSTYPE yylval;               /* Type of tokens */
static char *src;                    /* Source string */
static FILE *fp;                     /* Source file */
static int (*inp)();                 /* Pointer to input routine */
static int (*unp)();                 /* Pointer to unput routine */
static bool keywords;                /* True when scanning keywords */
static char *string,*ns;             /* Temporary strings */
static int nextLine, nextCol;        /* Next line and column number */
static char *srcString;              /* Start of source string */

static int Lookup();                 /* Look up a keyword */
static void SetFilePos();            /* Set the file position */

#ifdef LFU_DEBUG
static int PrintToken();             /* Print a token */
#endif

/**************************************************************************
  Keywords
**************************************************************************/

struct _KEYWORD {
  char *name;
  int tok;

} keys[] = {
  { "else",     T_ELSE },
  { "name",     T_NAME },
  { "owner",    T_OWNER },
  { "update",   T_UPDATE },
  { "ignore",   T_IGNORE },
  { "delete",   T_DELETE },
  { "preserve", T_PRESERVE },
  { "link",     T_LNK },
  { "log",      T_LOG },
  { "keep",     T_KEEP },
  { "force",    T_FORCE },
  { "fill",     T_FILL },
  { "chmod",    T_CHMOD },
  { "exec",     T_EXEC },
  { "shadow",   T_SHADOW },
  { "newtime",  T_NEWTIME },
  { "follow",   T_FOLLOW },
  { "compress", T_COMPRESS },
  { "type",     T_TYPE },
  { "exists",   T_EXISTS },
  { "group",    T_GROUP },
  { "source",   T_SOURCE },
  { "path",     T_PATH },
  { "logall",   T_LOGALL },
  { "chown",    T_CHOWN },
  { "chgrp",    T_CHGRP },
  { "error",    T_ERROR },
  { "warn",     T_WARN },
  { "inherit",  T_INHERIT },
  { "cdf",      T_CDF },
  { "stats",    T_STATS },
  { "newer",    T_NEWER },
  { "mode",     T_MODE },
  { "age",      T_AGE },
  { "access",   T_ACCESS },
  { "size",     T_SIZE },
  { "auto",     T_AUTO },
  { "nomount",  T_NOMOUNT },
  { "reboot",   T_REBOOT },
  { "default",  T_DEFAULT },
#ifdef LFU_CACHE
  { "cache",         T_CACHE },
  { "cacheminsize",  T_CACHEMINSIZE },
  { "cacheminfree",  T_CACHEMINFREE },
  { "cacheminvalue", T_CACHEMINVALUE },
  { "cachefile",     T_CACHEFILE },
  { "cachefill",     T_CACHEFILL },
#endif /* CACHE */
  { "noidcheck",     T_NOIDCHECK },
  { NULL,       T_STRING },
};

/**************************************************************************
  Scanner
**************************************************************************/

#define I 1
#define N 2
#define S 3

#line 573 "lex.yy.c"

/* Macros after this point can all be overridden by user definitions in
 * section 1.
 */

#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int yywrap YY_PROTO(( void ));
#else
extern int yywrap YY_PROTO(( void ));
#endif
#endif

#ifndef YY_NO_UNPUT
static void yyunput YY_PROTO(( int c, char *buf_ptr ));
#endif

#ifndef yytext_ptr
static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
#endif

#ifdef YY_NEED_STRLEN
static int yy_flex_strlen YY_PROTO(( yyconst char * ));
#endif

#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput YY_PROTO(( void ));
#else
static int input YY_PROTO(( void ));
#endif
#endif

#if YY_STACK_USED
static int yy_start_stack_ptr = 0;
static int yy_start_stack_depth = 0;
static int *yy_start_stack = 0;
#ifndef YY_NO_PUSH_STATE
static void yy_push_state YY_PROTO(( int new_state ));
#endif
#ifndef YY_NO_POP_STATE
static void yy_pop_state YY_PROTO(( void ));
#endif
#ifndef YY_NO_TOP_STATE
static int yy_top_state YY_PROTO(( void ));
#endif

#else
#define YY_NO_PUSH_STATE 1
#define YY_NO_POP_STATE 1
#define YY_NO_TOP_STATE 1
#endif

#ifdef YY_MALLOC_DECL
YY_MALLOC_DECL
#else
#if __STDC__
#ifndef __cplusplus
#include <stdlib.h>
#endif
#else
/* Just try to get by without declaring the routines.  This will fail
 * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
 * or sizeof(void*) != sizeof(int).
 */
#endif
#endif

/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif

/* Copy whatever the last rule matched to the standard output. */

#ifndef ECHO
/* This used to be an fputs(), but since the string might contain NUL's,
 * we now use fwrite().
 */
#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
#endif

/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
 * is returned in "result".
 */
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
	if ( yy_current_buffer->yy_is_interactive ) \
		{ \
		int c = '*', n; \
		for ( n = 0; n < max_size && \
			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
			buf[n] = (char) c; \
		if ( c == '\n' ) \
			buf[n++] = (char) c; \
		if ( c == EOF && ferror( yyin ) ) \
			YY_FATAL_ERROR( "input in flex scanner failed" ); \
		result = n; \
		} \
	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
		  && ferror( yyin ) ) \
		YY_FATAL_ERROR( "input in flex scanner failed" );
#endif

/* No semi-colon after return; correct usage is to write "yyterminate();" -
 * we don't want an extra ';' after the "return" because that will cause
 * some compilers to complain about unreachable statements.
 */
#ifndef yyterminate
#define yyterminate() return YY_NULL
#endif

/* Number of entries by which start-condition stack grows. */
#ifndef YY_START_STACK_INCR
#define YY_START_STACK_INCR 25
#endif

/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
#endif

/* Default declaration of generated scanner - a define so the user can
 * easily add parameters.
 */
#ifndef YY_DECL
#define YY_DECL int yylex YY_PROTO(( void ))
#endif

/* Code executed at the beginning of each rule, after yytext and yyleng
 * have been set up.
 */
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif

/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK break;
#endif

#define YY_RULE_SETUP \
	if ( yyleng > 0 ) \
		yy_current_buffer->yy_at_bol = \
				(yytext[yyleng - 1] == '\n'); \
	YY_USER_ACTION

YY_DECL
	{
	register yy_state_type yy_current_state;
	register char *yy_cp, *yy_bp;
	register int yy_act;

#line 171 "scan.l"

#line 729 "lex.yy.c"

	if ( yy_init )
		{
		yy_init = 0;

#ifdef YY_USER_INIT
		YY_USER_INIT;
#endif

		if ( ! yy_start )
			yy_start = 1;	/* first start state */

		if ( ! yyin )
			yyin = stdin;

		if ( ! yyout )
			yyout = stdout;

		if ( ! yy_current_buffer )
			yy_current_buffer =
				yy_create_buffer( yyin, YY_BUF_SIZE );

		yy_load_buffer_state();
		}

	while ( 1 )		/* loops until end-of-file is reached */
		{
		yy_cp = yy_c_buf_p;

		/* Support of yytext. */
		*yy_cp = yy_hold_char;

		/* yy_bp points to the position in yy_ch_buf of the start of
		 * the current run.
		 */
		yy_bp = yy_cp;

		yy_current_state = yy_start;
		yy_current_state += YY_AT_BOL();
yy_match:
		do
			{
			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
			if ( yy_accept[yy_current_state] )
				{
				yy_last_accepting_state = yy_current_state;
				yy_last_accepting_cpos = yy_cp;
				}
			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
				{
				yy_current_state = (int) yy_def[yy_current_state];
				if ( yy_current_state >= 51 )
					yy_c = yy_meta[(unsigned int) yy_c];
				}
			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
			++yy_cp;
			}
		while ( yy_base[yy_current_state] != 107 );

yy_find_action:
		yy_act = yy_accept[yy_current_state];
		if ( yy_act == 0 )
			{ /* have to back up */
			yy_cp = yy_last_accepting_cpos;
			yy_current_state = yy_last_accepting_state;
			yy_act = yy_accept[yy_current_state];
			}

		YY_DO_BEFORE_ACTION;


do_action:	/* This label is used only to access EOF actions. */


		switch ( yy_act )
	{ /* beginning of action switch */
			case 0: /* must back up */
			/* undo the effects of YY_DO_BEFORE_ACTION */
			*yy_cp = yy_hold_char;
			yy_cp = yy_last_accepting_cpos;
			yy_current_state = yy_last_accepting_state;
			goto yy_find_action;

case 1:
YY_RULE_SETUP
#line 172 "scan.l"
{ SetFilePos(yytext); BEGIN N; }
	YY_BREAK
case 2:
YY_RULE_SETUP
#line 173 "scan.l"
{ yyless(0); BEGIN N; }
	YY_BREAK
case 3:
YY_RULE_SETUP
#line 174 "scan.l"
{ Line(1); }
	YY_BREAK
case 4:
YY_RULE_SETUP
#line 175 "scan.l"
{ Col(strlen(yytext)); }
	YY_BREAK
case 5:
YY_RULE_SETUP
#line 176 "scan.l"
{ Col((nextCol+TABSIZE)%TABSIZE); }
	YY_BREAK
case 6:
YY_RULE_SETUP
#line 177 "scan.l"
{ SetFilePos(yytext); }
	YY_BREAK
case 7:
YY_RULE_SETUP
#line 178 "scan.l"
{ Col(1); Return(T_SEMI); }   
	YY_BREAK
case 8:
YY_RULE_SETUP
#line 179 "scan.l"
{ Col(1); Return(T_LBR); }    
	YY_BREAK
case 9:
YY_RULE_SETUP
#line 180 "scan.l"
{ Col(1); Return(T_RBR); }     
	YY_BREAK
case 10:
YY_RULE_SETUP
#line 181 "scan.l"
{ Col(1); Return(T_AND); }    
	YY_BREAK
case 11:
YY_RULE_SETUP
#line 182 "scan.l"
{ Col(1); Return(T_OR); }     
	YY_BREAK
case 12:
YY_RULE_SETUP
#line 183 "scan.l"
{ Col(1); Return(T_LPAR); }   
	YY_BREAK
case 13:
YY_RULE_SETUP
#line 184 "scan.l"
{ Col(1); Return(T_RPAR); }   
	YY_BREAK
case 14:
YY_RULE_SETUP
#line 185 "scan.l"
{ Col(1); Return(T_LSQ); }    
	YY_BREAK
case 15:
YY_RULE_SETUP
#line 186 "scan.l"
{ Col(1); Return(T_RSQ); }    
	YY_BREAK
case 16:
YY_RULE_SETUP
#line 187 "scan.l"
{ Col(1); Return(T_EQ); }     
	YY_BREAK
case 17:
YY_RULE_SETUP
#line 188 "scan.l"
{ Col(2); Return(T_NEQ); }    
	YY_BREAK
case 18:
YY_RULE_SETUP
#line 189 "scan.l"
{ Col(1); Return(T_NOT); }    
	YY_BREAK
case 19:
YY_RULE_SETUP
#line 190 "scan.l"
{ Col(1); Return(T_TILDE); }  
	YY_BREAK
case 20:
YY_RULE_SETUP
#line 191 "scan.l"
{ Col(1); Return(T_GT); }     
	YY_BREAK
case 21:
YY_RULE_SETUP
#line 192 "scan.l"
{ Col(1); Return(T_LT); }     
	YY_BREAK
case 22:
YY_RULE_SETUP
#line 193 "scan.l"
{ Col(strlen(yytext));
                     Return(Lookup(yytext)); }   
	YY_BREAK
case 23:
YY_RULE_SETUP
#line 196 "scan.l"
{ Col(1);
                     string=NewString("",NULL); BEGIN S; }
	YY_BREAK
case 24:
YY_RULE_SETUP
#line 198 "scan.l"
{ Col(strlen(yytext));
                     string=NewString(ns=string,yytext,NULL); free(ns); }
	YY_BREAK
case 25:
YY_RULE_SETUP
#line 200 "scan.l"
{ Col(2);
                     string=NewString(ns=string,"\n",NULL); free(ns); }
	YY_BREAK
case 26:
YY_RULE_SETUP
#line 202 "scan.l"
{ Col(2);
                     string=NewString(ns=string,"\t",NULL); free(ns); }
	YY_BREAK
case 27:
YY_RULE_SETUP
#line 204 "scan.l"
{ Line(1); }
	YY_BREAK
case 28:
YY_RULE_SETUP
#line 205 "scan.l"
{ Col(2);
                     string=NewString(ns=string,&yytext[1],NULL); free(ns); }
	YY_BREAK
case 29:
YY_RULE_SETUP
#line 207 "scan.l"
{ Col(1);
                     BEGIN N; Return(Lookup(string)); } 
	YY_BREAK
case 30:
YY_RULE_SETUP
#line 209 "scan.l"
{ Line(1);
                     if (fp!=NULL)
                        Fatal( E_FSTRING,FilePos(theFile,lineNo,colNo),NOSTR);
                     else Fatal( E_SSTRING, theString, NOSTR ); }
	YY_BREAK
case 31:
YY_RULE_SETUP
#line 213 "scan.l"
ECHO;
	YY_BREAK
#line 978 "lex.yy.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(I):
case YY_STATE_EOF(N):
case YY_STATE_EOF(S):
	yyterminate();

	case YY_END_OF_BUFFER:
		{
		/* Amount of text matched not including the EOB char. */
		int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;

		/* Undo the effects of YY_DO_BEFORE_ACTION. */
		*yy_cp = yy_hold_char;
		YY_RESTORE_YY_MORE_OFFSET

		if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
			{
			/* We're scanning a new file or input source.  It's
			 * possible that this happened because the user
			 * just pointed yyin at a new source and called
			 * yylex().  If so, then we have to assure
			 * consistency between yy_current_buffer and our
			 * globals.  Here is the right place to do so, because
			 * this is the first action (other than possibly a
			 * back-up) that will match for the new input source.
			 */
			yy_n_chars = yy_current_buffer->yy_n_chars;
			yy_current_buffer->yy_input_file = yyin;
			yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
			}

		/* Note that here we test for yy_c_buf_p "<=" to the position
		 * of the first EOB in the buffer, since yy_c_buf_p will
		 * already have been incremented past the NUL character
		 * (since all states make transitions on EOB to the
		 * end-of-buffer state).  Contrast this with the test
		 * in input().
		 */
		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
			{ /* This was really a NUL. */
			yy_state_type yy_next_state;

			yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;

			yy_current_state = yy_get_previous_state();

			/* Okay, we're now positioned to make the NUL
			 * transition.  We couldn't have
			 * yy_get_previous_state() go ahead and do it
			 * for us because it doesn't know how to deal
			 * with the possibility of jamming (and we don't
			 * want to build jamming into it because then it
			 * will run more slowly).
			 */

			yy_next_state = yy_try_NUL_trans( yy_current_state );

			yy_bp = yytext_ptr + YY_MORE_ADJ;

			if ( yy_next_state )
				{
				/* Consume the NUL. */
				yy_cp = ++yy_c_buf_p;
				yy_current_state = yy_next_state;
				goto yy_match;
				}

			else
				{
				yy_cp = yy_c_buf_p;
				goto yy_find_action;
				}
			}

		else switch ( yy_get_next_buffer() )
			{
			case EOB_ACT_END_OF_FILE:
				{
				yy_did_buffer_switch_on_eof = 0;

				if ( yywrap() )
					{
					/* Note: because we've taken care in
					 * yy_get_next_buffer() to have set up
					 * yytext, we can now set up
					 * yy_c_buf_p so that if some total
					 * hoser (like flex itself) wants to
					 * call the scanner after we return the
					 * YY_NULL, it'll still work - another
					 * YY_NULL will get returned.
					 */
					yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;

					yy_act = YY_STATE_EOF(YY_START);
					goto do_action;
					}

				else
					{
					if ( ! yy_did_buffer_switch_on_eof )
						YY_NEW_FILE;
					}
				break;
				}

			case EOB_ACT_CONTINUE_SCAN:
				yy_c_buf_p =
					yytext_ptr + yy_amount_of_matched_text;

				yy_current_state = yy_get_previous_state();

				yy_cp = yy_c_buf_p;
				yy_bp = yytext_ptr + YY_MORE_ADJ;
				goto yy_match;

			case EOB_ACT_LAST_MATCH:
				yy_c_buf_p =
				&yy_current_buffer->yy_ch_buf[yy_n_chars];

				yy_current_state = yy_get_previous_state();

				yy_cp = yy_c_buf_p;
				yy_bp = yytext_ptr + YY_MORE_ADJ;
				goto yy_find_action;
			}
		break;
		}

	default:
		YY_FATAL_ERROR(
			"fatal flex scanner internal error--no action found" );
	} /* end of action switch */
		} /* end of scanning one token */
	} /* end of yylex */


/* yy_get_next_buffer - try to read in a new buffer
 *
 * Returns a code representing an action:
 *	EOB_ACT_LAST_MATCH -
 *	EOB_ACT_CONTINUE_SCAN - continue scanning from current position
 *	EOB_ACT_END_OF_FILE - end of file
 */

static int yy_get_next_buffer()
	{
	register char *dest = yy_current_buffer->yy_ch_buf;
	register char *source = yytext_ptr;
	register int number_to_move, i;
	int ret_val;

	if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
		YY_FATAL_ERROR(
		"fatal flex scanner internal error--end of buffer missed" );

	if ( yy_current_buffer->yy_fill_buffer == 0 )
		{ /* Don't try to fill the buffer, so this is an EOF. */
		if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
			{
			/* We matched a single character, the EOB, so
			 * treat this as a final EOF.
			 */
			return EOB_ACT_END_OF_FILE;
			}

		else
			{
			/* We matched some text prior to the EOB, first
			 * process it.
			 */
			return EOB_ACT_LAST_MATCH;
			}
		}

	/* Try to read more data. */

	/* First move last chars to start of buffer. */
	number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;

	for ( i = 0; i < number_to_move; ++i )
		*(dest++) = *(source++);

	if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
		/* don't do the read, it's not guaranteed to return an EOF,
		 * just force an EOF
		 */
		yy_current_buffer->yy_n_chars = yy_n_chars = 0;

	else
		{
		int num_to_read =
			yy_current_buffer->yy_buf_size - number_to_move - 1;

		while ( num_to_read <= 0 )
			{ /* Not enough room in the buffer - grow it. */
#ifdef YY_USES_REJECT
			YY_FATAL_ERROR(
"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
#else

			/* just a shorter name for the current buffer */
			YY_BUFFER_STATE b = yy_current_buffer;

			int yy_c_buf_p_offset =
				(int) (yy_c_buf_p - b->yy_ch_buf);

			if ( b->yy_is_our_buffer )
				{
				int new_size = b->yy_buf_size * 2;

				if ( new_size <= 0 )
					b->yy_buf_size += b->yy_buf_size / 8;
				else
					b->yy_buf_size *= 2;

				b->yy_ch_buf = (char *)
					/* Include room in for 2 EOB chars. */
					yy_flex_realloc( (void *) b->yy_ch_buf,
							 b->yy_buf_size + 2 );
				}
			else
				/* Can't grow it, we don't own it. */
				b->yy_ch_buf = 0;

			if ( ! b->yy_ch_buf )
				YY_FATAL_ERROR(
				"fatal error - scanner input buffer overflow" );

			yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];

			num_to_read = yy_current_buffer->yy_buf_size -
						number_to_move - 1;
#endif
			}

		if ( num_to_read > YY_READ_BUF_SIZE )
			num_to_read = YY_READ_BUF_SIZE;

		/* Read in more data. */
		YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
			yy_n_chars, num_to_read );

		yy_current_buffer->yy_n_chars = yy_n_chars;
		}

	if ( yy_n_chars == 0 )
		{
		if ( number_to_move == YY_MORE_ADJ )
			{
			ret_val = EOB_ACT_END_OF_FILE;
			yyrestart( yyin );
			}

		else
			{
			ret_val = EOB_ACT_LAST_MATCH;
			yy_current_buffer->yy_buffer_status =
				YY_BUFFER_EOF_PENDING;
			}
		}

	else
		ret_val = EOB_ACT_CONTINUE_SCAN;

	yy_n_chars += number_to_move;
	yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
	yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;

	yytext_ptr = &yy_current_buffer->yy_ch_buf[0];

	return ret_val;
	}


/* yy_get_previous_state - get the state just before the EOB char was reached */

static yy_state_type yy_get_previous_state()
	{
	register yy_state_type yy_current_state;
	register char *yy_cp;

	yy_current_state = yy_start;
	yy_current_state += YY_AT_BOL();

	for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
		{
		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
		if ( yy_accept[yy_current_state] )
			{
			yy_last_accepting_state = yy_current_state;
			yy_last_accepting_cpos = yy_cp;
			}
		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
			{
			yy_current_state = (int) yy_def[yy_current_state];
			if ( yy_current_state >= 51 )
				yy_c = yy_meta[(unsigned int) yy_c];
			}
		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
		}

	return yy_current_state;
	}


/* yy_try_NUL_trans - try to make a transition on the NUL character
 *
 * synopsis
 *	next_state = yy_try_NUL_trans( current_state );
 */

#ifdef YY_USE_PROTOS
static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
#else
static yy_state_type yy_try_NUL_trans( yy_current_state )
yy_state_type yy_current_state;
#endif
	{
	register int yy_is_jam;
	register char *yy_cp = yy_c_buf_p;

	register YY_CHAR yy_c = 1;
	if ( yy_accept[yy_current_state] )
		{
		yy_last_accepting_state = yy_current_state;
		yy_last_accepting_cpos = yy_cp;
		}
	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
		{
		yy_current_state = (int) yy_def[yy_current_state];
		if ( yy_current_state >= 51 )
			yy_c = yy_meta[(unsigned int) yy_c];
		}
	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
	yy_is_jam = (yy_current_state == 50);

	return yy_is_jam ? 0 : yy_current_state;
	}


#ifndef YY_NO_UNPUT
#ifdef YY_USE_PROTOS
static void yyunput( int c, register char *yy_bp )
#else
static void yyunput( c, yy_bp )
int c;
register char *yy_bp;
#endif
	{
	register char *yy_cp = yy_c_buf_p;

	/* undo effects of setting up yytext */
	*yy_cp = yy_hold_char;

	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
		{ /* need to shift things up to make room */
		/* +2 for EOB chars. */
		register int number_to_move = yy_n_chars + 2;
		register char *dest = &yy_current_buffer->yy_ch_buf[
					yy_current_buffer->yy_buf_size + 2];
		register char *source =
				&yy_current_buffer->yy_ch_buf[number_to_move];

		while ( source > yy_current_buffer->yy_ch_buf )
			*--dest = *--source;

		yy_cp += (int) (dest - source);
		yy_bp += (int) (dest - source);
		yy_current_buffer->yy_n_chars =
			yy_n_chars = yy_current_buffer->yy_buf_size;

		if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
			YY_FATAL_ERROR( "flex scanner push-back overflow" );
		}

	*--yy_cp = (char) c;


	yytext_ptr = yy_bp;
	yy_hold_char = *yy_cp;
	yy_c_buf_p = yy_cp;
	}
#endif	/* ifndef YY_NO_UNPUT */


#ifdef __cplusplus
static int yyinput()
#else
static int input()
#endif
	{
	int c;

	*yy_c_buf_p = yy_hold_char;

	if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
		{
		/* yy_c_buf_p now points to the character we want to return.
		 * If this occurs *before* the EOB characters, then it's a
		 * valid NUL; if not, then we've hit the end of the buffer.
		 */
		if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
			/* This was really a NUL. */
			*yy_c_buf_p = '\0';

		else
			{ /* need more input */
			int offset = yy_c_buf_p - yytext_ptr;
			++yy_c_buf_p;

			switch ( yy_get_next_buffer() )
				{
				case EOB_ACT_LAST_MATCH:
					/* This happens because yy_g_n_b()
					 * sees that we've accumulated a
					 * token and flags that we need to
					 * try matching the token before
					 * proceeding.  But for input(),
					 * there's no matching to consider.
					 * So convert the EOB_ACT_LAST_MATCH
					 * to EOB_ACT_END_OF_FILE.
					 */

					/* Reset buffer status. */
					yyrestart( yyin );

					/* fall through */

				case EOB_ACT_END_OF_FILE:
					{
					if ( yywrap() )
						return EOF;

					if ( ! yy_did_buffer_switch_on_eof )
						YY_NEW_FILE;
#ifdef __cplusplus
					return yyinput();
#else
					return input();
#endif
					}

				case EOB_ACT_CONTINUE_SCAN:
					yy_c_buf_p = yytext_ptr + offset;
					break;
				}
			}
		}

	c = *(unsigned char *) yy_c_buf_p;	/* cast for 8-bit char's */
	*yy_c_buf_p = '\0';	/* preserve yytext */
	yy_hold_char = *++yy_c_buf_p;

	yy_current_buffer->yy_at_bol = (c == '\n');

	return c;
	}


#ifdef YY_USE_PROTOS
void yyrestart( FILE *input_file )
#else
void yyrestart( input_file )
FILE *input_file;
#endif
	{
	if ( ! yy_current_buffer )
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );

	yy_init_buffer( yy_current_buffer, input_file );
	yy_load_buffer_state();
	}


#ifdef YY_USE_PROTOS
void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
#else
void yy_switch_to_buffer( new_buffer )
YY_BUFFER_STATE new_buffer;
#endif
	{
	if ( yy_current_buffer == new_buffer )
		return;

	if ( yy_current_buffer )
		{
		/* Flush out information for old buffer. */
		*yy_c_buf_p = yy_hold_char;
		yy_current_buffer->yy_buf_pos = yy_c_buf_p;
		yy_current_buffer->yy_n_chars = yy_n_chars;
		}

	yy_current_buffer = new_buffer;
	yy_load_buffer_state();

	/* We don't actually know whether we did this switch during
	 * EOF (yywrap()) processing, but the only time this flag
	 * is looked at is after yywrap() is called, so it's safe
	 * to go ahead and always set it.
	 */
	yy_did_buffer_switch_on_eof = 1;
	}


#ifdef YY_USE_PROTOS
void yy_load_buffer_state( void )
#else
void yy_load_buffer_state()
#endif
	{
	yy_n_chars = yy_current_buffer->yy_n_chars;
	yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
	yyin = yy_current_buffer->yy_input_file;
	yy_hold_char = *yy_c_buf_p;
	}


#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
#else
YY_BUFFER_STATE yy_create_buffer( file, size )
FILE *file;
int size;
#endif
	{
	YY_BUFFER_STATE b;

	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );

	b->yy_buf_size = size;

	/* yy_ch_buf has to be 2 characters longer than the size given because
	 * we need to put in 2 end-of-buffer characters.
	 */
	b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
	if ( ! b->yy_ch_buf )
		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );

	b->yy_is_our_buffer = 1;

	yy_init_buffer( b, file );

	return b;
	}


#ifdef YY_USE_PROTOS
void yy_delete_buffer( YY_BUFFER_STATE b )
#else
void yy_delete_buffer( b )
YY_BUFFER_STATE b;
#endif
	{
	if ( ! b )
		return;

	if ( b == yy_current_buffer )
		yy_current_buffer = (YY_BUFFER_STATE) 0;

	if ( b->yy_is_our_buffer )
		yy_flex_free( (void *) b->yy_ch_buf );

	yy_flex_free( (void *) b );
	}


#ifndef YY_ALWAYS_INTERACTIVE
#ifndef YY_NEVER_INTERACTIVE
extern int isatty YY_PROTO(( int ));
#endif
#endif

#ifdef YY_USE_PROTOS
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
#else
void yy_init_buffer( b, file )
YY_BUFFER_STATE b;
FILE *file;
#endif


	{
	yy_flush_buffer( b );

	b->yy_input_file = file;
	b->yy_fill_buffer = 1;

#if YY_ALWAYS_INTERACTIVE
	b->yy_is_interactive = 1;
#else
#if YY_NEVER_INTERACTIVE
	b->yy_is_interactive = 0;
#else
	b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
#endif
#endif
	}


#ifdef YY_USE_PROTOS
void yy_flush_buffer( YY_BUFFER_STATE b )
#else
void yy_flush_buffer( b )
YY_BUFFER_STATE b;
#endif

	{
	if ( ! b )
		return;

	b->yy_n_chars = 0;

	/* We always need two end-of-buffer characters.  The first causes
	 * a transition to the end-of-buffer state.  The second causes
	 * a jam in that state.
	 */
	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;

	b->yy_buf_pos = &b->yy_ch_buf[0];

	b->yy_at_bol = 1;
	b->yy_buffer_status = YY_BUFFER_NEW;

	if ( b == yy_current_buffer )
		yy_load_buffer_state();
	}


#ifndef YY_NO_SCAN_BUFFER
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
#else
YY_BUFFER_STATE yy_scan_buffer( base, size )
char *base;
yy_size_t size;
#endif
	{
	YY_BUFFER_STATE b;

	if ( size < 2 ||
	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
	     base[size-1] != YY_END_OF_BUFFER_CHAR )
		/* They forgot to leave room for the EOB's. */
		return 0;

	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );

	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
	b->yy_buf_pos = b->yy_ch_buf = base;
	b->yy_is_our_buffer = 0;
	b->yy_input_file = 0;
	b->yy_n_chars = b->yy_buf_size;
	b->yy_is_interactive = 0;
	b->yy_at_bol = 1;
	b->yy_fill_buffer = 0;
	b->yy_buffer_status = YY_BUFFER_NEW;

	yy_switch_to_buffer( b );

	return b;
	}
#endif


#ifndef YY_NO_SCAN_STRING
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
#else
YY_BUFFER_STATE yy_scan_string( yy_str )
yyconst char *yy_str;
#endif
	{
	int len;
	for ( len = 0; yy_str[len]; ++len )
		;

	return yy_scan_bytes( yy_str, len );
	}
#endif


#ifndef YY_NO_SCAN_BYTES
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
#else
YY_BUFFER_STATE yy_scan_bytes( bytes, len )
yyconst char *bytes;
int len;
#endif
	{
	YY_BUFFER_STATE b;
	char *buf;
	yy_size_t n;
	int i;

	/* Get memory for full buffer, including space for trailing EOB's. */
	n = len + 2;
	buf = (char *) yy_flex_alloc( n );
	if ( ! buf )
		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );

	for ( i = 0; i < len; ++i )
		buf[i] = bytes[i];

	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;

	b = yy_scan_buffer( buf, n );
	if ( ! b )
		YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );

	/* It's okay to grow etc. this buffer, and we should throw it
	 * away when we're done.
	 */
	b->yy_is_our_buffer = 1;

	return b;
	}
#endif


#ifndef YY_NO_PUSH_STATE
#ifdef YY_USE_PROTOS
static void yy_push_state( int new_state )
#else
static void yy_push_state( new_state )
int new_state;
#endif
	{
	if ( yy_start_stack_ptr >= yy_start_stack_depth )
		{
		yy_size_t new_size;

		yy_start_stack_depth += YY_START_STACK_INCR;
		new_size = yy_start_stack_depth * sizeof( int );

		if ( ! yy_start_stack )
			yy_start_stack = (int *) yy_flex_alloc( new_size );

		else
			yy_start_stack = (int *) yy_flex_realloc(
					(void *) yy_start_stack, new_size );

		if ( ! yy_start_stack )
			YY_FATAL_ERROR(
			"out of memory expanding start-condition stack" );
		}

	yy_start_stack[yy_start_stack_ptr++] = YY_START;

	BEGIN(new_state);
	}
#endif


#ifndef YY_NO_POP_STATE
static void yy_pop_state()
	{
	if ( --yy_start_stack_ptr < 0 )
		YY_FATAL_ERROR( "start-condition stack underflow" );

	BEGIN(yy_start_stack[yy_start_stack_ptr]);
	}
#endif


#ifndef YY_NO_TOP_STATE
static int yy_top_state()
	{
	return yy_start_stack[yy_start_stack_ptr - 1];
	}
#endif

#ifndef YY_EXIT_FAILURE
#define YY_EXIT_FAILURE 2
#endif

#ifdef YY_USE_PROTOS
static void yy_fatal_error( yyconst char msg[] )
#else
static void yy_fatal_error( msg )
char msg[];
#endif
	{
	(void) fprintf( stderr, "%s\n", msg );
	exit( YY_EXIT_FAILURE );
	}



/* Redefine yyless() so it works in section 3 code. */

#undef yyless
#define yyless(n) \
	do \
		{ \
		/* Undo effects of setting up yytext. */ \
		yytext[yyleng] = yy_hold_char; \
		yy_c_buf_p = yytext + n; \
		yy_hold_char = *yy_c_buf_p; \
		*yy_c_buf_p = '\0'; \
		yyleng = n; \
		} \
	while ( 0 )


/* Internal utility routines. */

#ifndef yytext_ptr
#ifdef YY_USE_PROTOS
static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
#else
static void yy_flex_strncpy( s1, s2, n )
char *s1;
yyconst char *s2;
int n;
#endif
	{
	register int i;
	for ( i = 0; i < n; ++i )
		s1[i] = s2[i];
	}
#endif

#ifdef YY_NEED_STRLEN
#ifdef YY_USE_PROTOS
static int yy_flex_strlen( yyconst char *s )
#else
static int yy_flex_strlen( s )
yyconst char *s;
#endif
	{
	register int n;
	for ( n = 0; s[n]; ++n )
		;

	return n;
	}
#endif


#ifdef YY_USE_PROTOS
static void *yy_flex_alloc( yy_size_t size )
#else
static void *yy_flex_alloc( size )
yy_size_t size;
#endif
	{
	return (void *) malloc( size );
	}

#ifdef YY_USE_PROTOS
static void *yy_flex_realloc( void *ptr, yy_size_t size )
#else
static void *yy_flex_realloc( ptr, size )
void *ptr;
yy_size_t size;
#endif
	{
	/* The cast to (char *) in the following accommodates both
	 * implementations that use char* generic pointers, and those
	 * that use void* generic pointers.  It works with the latter
	 * because both ANSI C and C++ allow castless assignment from
	 * any pointer type to void*, and deal with argument conversions
	 * as though doing an assignment.
	 */
	return (void *) realloc( (char *) ptr, size );
	}

#ifdef YY_USE_PROTOS
static void yy_flex_free( void *ptr )
#else
static void yy_flex_free( ptr )
void *ptr;
#endif
	{
	free( ptr );
	}

#if YY_MAIN
int main()
	{
	yylex();
	return 0;
	}
#endif
#line 213 "scan.l"


#ifdef LFU_DEBUG
#define PAGEWIDTH 80
  static char buf[PAGEWIDTH+1];
  static char *bp=buf;
  static int backup=0;
#endif

/*************************************************************************/
  static int FileInput()
/*************************************************************************/
{
  register char c=getc(fp);

#ifdef LFU_DEBUG

  if (DebugFlag(D_INPUT)) {
    if (backup>0) --backup;
    else {
      if ((c=='\n') || (c==EOF) || (bp>&buf[PAGEWIDTH])) {
        char *p;
        fprintf( stdout, "--: input: " );
        for (p=buf; p<bp; ++p) putchar(*p);
        putchar('\n');
        bp=buf;
      }
      if ((c!='\n') && (c!=EOF)) *bp++=c;
    }
  }
#endif
  if (c!=EOF) return c;
  Col(0); return 0;
}

/*************************************************************************/
  static int StringInput()
/*************************************************************************/
{
  if (*src) return *src++;
  Col(0); return 0;
}

/*************************************************************************/
  static int FileUnput(c)
/*************************************************************************/
char c;
{
#ifdef LFU_DEBUG
  if (DebugFlag(D_INPUT)) ++backup;
#endif
  (void)ungetc(c,fp);
  return c;
}

/*************************************************************************/
  static int StringUnput(c)
/*************************************************************************/
char c;
{
  *--src=(c);
  return c;
}

/*************************************************************************/
  /*ARGSUSED*/ static int Output(c)
/*************************************************************************/
char c;
{
  if (fp!=NULL) Fatal( E_FSCAN, FilePos(theFile, lineNo, colNo), NOSTR );
  else Fatal( E_SSCAN, theString, NOSTR );
  /*NOTREACHED*/ return 0;
}

/*************************************************************************/
  static void Scan()
/*************************************************************************/
{
  BEGIN I;
  nextLine=2;
  lineNo=1;
  nextCol=colNo=0;
  keywords=true;
}

/*************************************************************************/
  void ScanString(str)
/*************************************************************************/
char *str;
{
  theString=str;
  theFile=NULL;
  inp=StringInput;
  unp=StringUnput; 
  srcString=src=NewString(str,NULL);
  fp=NULL;
  Scan();
}

/*************************************************************************/
  void ScanFile(fname)
/*************************************************************************/
char *fname;
{
  theString=NULL;
  theFile=NewString(fname,NULL);
  inp=FileInput;
  unp=FileUnput;
  fp=ExecCPP(fname);
  src=fname;
  Scan();
}

/*************************************************************************/
  void EndScan()
/*************************************************************************/
{
  WAITSTAT status;

  if (fp==NULL) free(srcString);
  else {

    free(theFile);

    status=ExecClose(fp);
    if (WAITVAL(status) == (-1)) Fatal( E_WAIT, cpp, NOSTR );
    else if (WIFSIGNALED(status) || WIFSTOPPED(status)) exit(1);
    else if (WIFEXITED(status)) {
      if (WEXITSTATUS(status)==127) Fatal( E_CPP, cpp, NOSTR );
      else if (WEXITSTATUS(status)!=0 ) exit(1);
    }
  }
}

/*************************************************************************/
  void StartString()
/*************************************************************************/
{
  keywords=false;
}

/*************************************************************************/
  void EndString()
/*************************************************************************/
{
  keywords=true;
}

/*************************************************************************/
  static int Lookup(key)
/*************************************************************************/
char *key;
{
  register struct _KEYWORD *k=keys;
  int token;

  if (keywords) {
    while (k->name!=NULL && strcmp(key,k->name)) ++k;
    token = k->tok;
  } else token = T_STRING;
  yylval.string=(token==T_STRING && key==(char*)yytext)
    ? NewString(key,NULL) : key;
  return token;  
}

/*************************************************************************/
  static void SetFilePos(str)
/*************************************************************************/
char *str;
{
  char bufr[MAXPATHLEN+1];
  int l, matches;

  if (fp==NULL) return;

  if ((matches=sscanf(str, "# %d \"%[^\"]\"", &l, bufr)) > 0 ) {
    free(theFile);
    if (matches>1) theFile = NewString(bufr,NULL);
    else theFile=NewString("-",NULL);
    lineNo = l;
    nextLine = l;
    colNo = 0;
    nextCol = 0;
  } else Line(1);
}

/*************************************************************************/
  char *FilePos(name, line, col)
/*************************************************************************/
char *name;
int line, col;
{
  static char bufr[MAXPATHLEN+32];

  (void)sprintf( bufr, "#%d.%d %s", line, col, 
	         (*name=='\0' || !strcmp(name,"-")) ? "<stdin>" : name );
  return bufr;
}

#ifdef LFU_DEBUG

/*************************************************************************/
  static char *TokenName(tok)
/*************************************************************************/
int tok;
{
  static char buf[32];

  switch (tok) {
#include "toklist.h"
  default: (void)sprintf( buf, "T_%d", tok ); return buf;
  }
}

/*************************************************************************/
  static int PrintToken(tok)
/*************************************************************************/
int tok;
{
  if (DebugFlag(D_SCAN)) {
    (void)fprintf(stdout, "--: scan: [%02d:%02d] %s (%s)\n",
                  lineNo, colNo, TokenName(tok),
		  (tok==T_STRING) ? yylval.string : (char*)yytext );
  }
  return tok;
}

#endif /* LFUDEBUG */
lfu-3.1.5/src/avl.c   644  75362  74430       36727  6510207075   7264 /**************************************************************************

  This code implements threaded AVL trees.

  $Author: paul $
  $Revision: 1.4 $
  $Date: 1998/03/31 15:39:07 $

  Copyright (c) 1992 by the University of Edinburgh
  Laboratory for the Foundations of Computer Science
  Department of Computer Science
  Written by Paul Anderson.

  Permission is granted to anyone to use this software for any
  purpose on any computer system, and to redistribute it freely,
  subject to the following restrictions:

  The University of Edinburgh makes no representations about the
  suitability of this software for any purpose.  It is
  provided "as is" without express or implied warranty.

  The origin of this software must not be misrepresented, either by
  explicit claim or by omission, and this copyright notice must appear in
  all copies of the software. Altered versions must be plainly marked
  as such, and must not be misrepresented as being the original software.

  The name of the University of Edinburgh must not be used in
  advertising or publicity pertaining to distribution of the software
  without specific, written prior permission. 
 
**************************************************************************/

/*LINTLIBRARY*/

#define _AVL_C

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include "misc.h"
#include "avl.h"

/**************************************************************************
  Internal Macros
**************************************************************************/

#define lthread(np)        ((np)->flags & LTHREADBIT)
#define rthread(np)        ((np)->flags & RTHREADBIT)
#define bf(np)             ((np)->flags & AVLBALANCEMASK)
#define set_lthread(np)    ((np)->flags |= LTHREADBIT)
#define set_rthread(np)    ((np)->flags |= RTHREADBIT)
#define clr_lthread(np)    ((np)->flags &= ~LTHREADBIT)
#define clr_rthread(np)    ((np)->flags &= ~RTHREADBIT)
#define set_bf(np,t)       ((np)->flags = ((np)->flags&~AVLBALANCEMASK)|(t))

/**************************************************************************
  Globals
**************************************************************************/

static int unbalanced;              /* non-zero when tree is unbalanced */
static int already_found;           /* flag for deletions */
static AVL_NODE found;              /* target node of an ins/del */

/*************************************************************************/
  static AVL_NODE AVL_NewNode(k,v)
/*************************************************************************/
AVL_KEY k;
AVL_VALUE v;
{
  AVL_NODE np=(AVL_NODE)NewMem((int)(sizeof *np));
  if (np!=NULL) {
    np->k=k;
    np->v=v;
    np->lt=NULL;
    np->rt=NULL;
    np->flags=LTHREADBIT|RTHREADBIT|AVLBALANCED;
  }
  return np;
}

/*************************************************************************/
  static void AVL_Insert(k,v,npp,t)
/*************************************************************************/
AVL_KEY k;
AVL_VALUE v;
AVL_NODE *npp;
AVL_TREE t;
{
  AVL_NODE l,r,np= *npp;
  int comp = t->compFn(k, np->k);

  if (comp == 0){
    found = np;
    return;
  } else if (comp < 0) {
    if (lthread(np)) {
      ++t->count;
      found = AVL_NewNode(k,v);
      found->lt = np->lt;
      found->rt = np;
      np->lt = found;
      clr_lthread(np);
      unbalanced = 1;

    } else AVL_Insert(k,v,&(np->lt),t);

    if (unbalanced) {
      switch(bf(np)) {
      case AVLRIGHTHEAVY:
        set_bf(np, AVLBALANCED);
        unbalanced = 0;
        return;
      case AVLBALANCED:
        set_bf(np, AVLLEFTHEAVY);
        return;
      case AVLLEFTHEAVY:
        l = np->lt;
        if (bf(l) == AVLLEFTHEAVY) {
	  np->lt = (rthread(l)) ? l : l->rt;
          if (rthread(l)) set_lthread(np); else clr_lthread(np);
          l->rt = np;
          clr_rthread(l);
          set_bf(np, AVLBALANCED);
          set_bf(l,  AVLBALANCED);
          *npp = l;
          unbalanced = 0;
	  return;
        } else {
          r = l->rt;
          if (lthread(r)) set_rthread(l); else clr_rthread(l);
	  l->rt = (lthread(r)) ? r : r->lt;
          r->lt = l;
          clr_lthread(r);
          if (rthread(r)) set_lthread(np); else clr_lthread(np);
	  np->lt = (rthread(r)) ? r : r->rt;
          r->rt = np;
          clr_rthread(r);
	  set_bf(np, ((bf(r)==AVLLEFTHEAVY)  ? AVLRIGHTHEAVY : AVLBALANCED));
	  set_bf(l,  ((bf(r)==AVLRIGHTHEAVY) ? AVLLEFTHEAVY  : AVLBALANCED));
	  set_bf(r,  AVLBALANCED);
          *npp = r;
          unbalanced = 0;
          return;
        }
      }
    }
  } else {
    if (rthread(np)) {
      ++t->count;
      found = AVL_NewNode(k,v);
      clr_rthread(np);
      found->lt = np;
      found->rt = np->rt;
      np->rt = found;
      unbalanced = 1;

    } else AVL_Insert(k,v,&(np->rt),t);

    if (unbalanced) {
      switch(bf(np)) {
      case AVLLEFTHEAVY:
        set_bf(np, AVLBALANCED);
        unbalanced = 0;
        return;
      case AVLBALANCED:
        set_bf(np, AVLRIGHTHEAVY);
        return;
      case AVLRIGHTHEAVY:
        r = np->rt;
        if (bf(r) == AVLRIGHTHEAVY) {
	  np->rt = (lthread(r)) ? r : r->lt;
	  if (lthread(r)) set_rthread(np); else clr_rthread(np);
	  r->lt = np;
          clr_lthread(r);
          set_bf(np, AVLBALANCED);
          set_bf(r,  AVLBALANCED);
          *npp = r;
          unbalanced = 0;
	  return;
        } else {
          l = r->lt;
          if (rthread(l)) set_lthread(r); else clr_lthread(r);
	  r->lt = (rthread(l)) ? l : l->rt;
          l->rt = r;
          clr_rthread(l);
          if (lthread(l)) set_rthread(np); else clr_rthread(np);
	  np->rt = (lthread(l)) ? l : l->lt;
          l->lt = np;
          clr_lthread(l);
	  set_bf(np, ((bf(l)==AVLRIGHTHEAVY) ? AVLLEFTHEAVY  : AVLBALANCED ));
	  set_bf(r,  ((bf(l)==AVLLEFTHEAVY)  ? AVLRIGHTHEAVY : AVLBALANCED ));
          set_bf(l, AVLBALANCED);
          *npp = l;
          unbalanced = 0;
          return;
        }
      }
    }
  }
}

/*************************************************************************/
  static void AVL_Delete(k,par,npp,t)
/*************************************************************************/
AVL_KEY k;
AVL_NODE par,*npp;
AVL_TREE t;
{
  AVL_NODE l,r,s,p,np= *npp;
  int comp;

  if (already_found) comp = (rthread(np)) ? 0 : 1;
  else comp = t->compFn(k,np->k);

  if (comp==0) {
    if (lthread(np) && rthread(np)) {
      found = np;
      if (np==par->lt) {
        set_lthread(par);
        par->lt = np->lt;
      } else {
        set_rthread(par);
        par->rt = np->rt;
      }
      unbalanced = 1;
      return;

    } else if (lthread(np)) {
      found = np;
      s = AVL_Next(np);
      if (s!=NULL && lthread(s))
        s->lt = np->lt;
      *npp = np->rt;
      unbalanced = 1;
      return;

    } else if (rthread(np)) {
      found = np;
      p = AVL_Prev(np);
      if (p!=NULL && rthread(p))
        p->rt = np->rt;
      *npp = np->lt;
      unbalanced = 1;
      return;

    } else {
      p = AVL_Prev(np);
      np->k = p->k;
      np->v = p->v;
      already_found = 1;
      comp = -1;
    }
  }

  if (comp<0) {
    if (lthread(np)) return;
    AVL_Delete(k,np,&(np->lt),t);
    if (!unbalanced) return;
    switch (bf(np)) {
    case AVLLEFTHEAVY:
      set_bf(np, AVLBALANCED);
      return;
    case AVLBALANCED:
      set_bf(np, AVLRIGHTHEAVY);
      unbalanced = 0;
      return;
    case AVLRIGHTHEAVY:
      r = np->rt;
      switch (bf(r)) {
      case AVLBALANCED:
	np->rt = (lthread(r)) ? r : r->lt;
	if (lthread(r)) set_rthread(np); else clr_rthread(np);
        r->lt = np;
        clr_lthread(r);
        set_bf(np, AVLRIGHTHEAVY);
        set_bf(r,  AVLLEFTHEAVY);
        unbalanced = 0;
        *npp = r;
        return;
      case AVLRIGHTHEAVY:
	np->rt  = (lthread(r)) ? r : r->lt;
	if (lthread(r)) set_rthread(np); else clr_rthread(np);
        r->lt = np;
        clr_lthread(r);
        set_bf(np, AVLBALANCED);
        set_bf(r,  AVLBALANCED);
        *npp = r;
        return;
      case AVLLEFTHEAVY:
        l = r->lt;
	if (rthread(l)) set_lthread(r); else clr_lthread(r);
	r->lt = (rthread(l)) ? l : l->rt;
        l->rt = r;
        clr_rthread(l);
	if (lthread(l)) set_rthread(np); else clr_rthread(np);
	np->rt = (lthread(l)) ? l : l->lt;
        l->lt = np;
        clr_lthread(l);
	set_bf(np, (bf(l)==AVLRIGHTHEAVY) ? AVLLEFTHEAVY : AVLBALANCED );
	set_bf(r,  (bf(l)==AVLLEFTHEAVY) ? AVLRIGHTHEAVY : AVLBALANCED );
        set_bf(l, AVLBALANCED);
        *npp = l;
        return;
      }
    }
  } else {
    if (rthread(np)) return;
    AVL_Delete(k,np,&(np->rt),t);
    if (!unbalanced) return;

    switch (bf(np)) {
    case AVLRIGHTHEAVY:
      set_bf(np, AVLBALANCED);
      return;
    case AVLBALANCED:
      set_bf(np, AVLLEFTHEAVY);
      unbalanced = 0;
      return;
    case AVLLEFTHEAVY:
      l = np->lt;
      switch (bf(l)) {
      case AVLBALANCED:
	np->lt = (rthread(l)) ? l : l->rt;
	if (rthread(l)) set_lthread(np); else clr_lthread(np);
        l->rt = np;
        clr_rthread(l);
        set_bf(np, AVLLEFTHEAVY);
        set_bf(l, AVLRIGHTHEAVY);
        unbalanced = 0;
        *npp = l;
        return;
      case AVLLEFTHEAVY:
	np->lt = (rthread(l)) ? l : l->rt;
	if (rthread(l)) set_lthread(np); else clr_lthread(np);
        l->rt = np;
        clr_rthread(l);
        set_bf(np, AVLBALANCED);
        set_bf(l,  AVLBALANCED);
        *npp = l;
        return;
      case AVLRIGHTHEAVY:
        r = l->rt;
	if (lthread(r)) set_rthread(l); else clr_rthread(l);
	l->rt = (lthread(r)) ? r : r->lt;
        r->lt = l;
        clr_lthread(r);
	if (rthread(r)) set_lthread(np); else clr_lthread(np);
	np->lt = (rthread(r)) ? r : r->rt;
        r->rt = np;
        clr_rthread(r);
	set_bf(np, (bf(r)==AVLLEFTHEAVY) ? AVLRIGHTHEAVY : AVLBALANCED );
	set_bf(l,  (bf(r)==AVLRIGHTHEAVY) ? AVLLEFTHEAVY : AVLBALANCED );
        set_bf(r,  AVLBALANCED);
        *npp = r;
        return;
      }
    }
  }
}

/*************************************************************************/
  AVL_TREE AVL_NewTree(fn)
/*************************************************************************/
INTFN *fn;
{
  AVL_TREE t=(AVL_TREE)NewMem((int)(sizeof *t));
  if (t!=(AVL_TREE)0) {
    t->count=0;
    t->compFn=fn;
    t->root=NULL;
  }
  return t;
}

/*************************************************************************/
  AVL_NODE AVL_Add(k,v,t)
/*************************************************************************/
AVL_KEY k;
AVL_VALUE v;
AVL_TREE t;
{
  if (t->root==NULL) {
    ++t->count;
    t->root = AVL_NewNode(k,v);
    return t->root;
  } else {
    unbalanced = 0;
    AVL_Insert(k,v,&(t->root),t);
    return found;
  }
}

/*************************************************************************/
  void AVL_Remove(k,t)
/*************************************************************************/
AVL_KEY k;
AVL_TREE t;
{
  if (t->root==NULL) return;
  unbalanced = 0;
  already_found = 0;
  found = NULL;
  AVL_Delete(k,t->root,&(t->root),t);

  if (found!=NULL) {
    free((char*)found);
    if (--t->count == 0) t->root = NULL;
  }
}

/*************************************************************************/
  AVL_NODE AVL_First(t)
/*************************************************************************/
AVL_TREE t;
{
  AVL_NODE np=t->root;
  if (np!=NULL) while (np->lt!=NULL) np=np->lt;
  return np;
}

/*************************************************************************/
  AVL_NODE AVL_Last(t)
/*************************************************************************/
AVL_TREE t;
{
  AVL_NODE np=t->root;
  if (np!=NULL) while (np->rt!=NULL) np=np->rt;
  return np;
}

/*************************************************************************/
  AVL_NODE AVL_Next(np)
/*************************************************************************/
AVL_NODE np;
{
 AVL_NODE r=np->rt;
 if (!rthread(np)) while (!lthread(r)) r=r->lt;
 return r;
}

/*************************************************************************/
  AVL_NODE AVL_Prev(np)
/*************************************************************************/
AVL_NODE np;
{
 AVL_NODE l=np->lt;
 if (!lthread(np)) while (!rthread(l)) l=l->rt;
 return l;
}

/*************************************************************************/
  AVL_NODE AVL_Lookup(k,t)
/*************************************************************************/
AVL_KEY k;
AVL_TREE t;
{
  AVL_NODE np;

  if (t==NULL) return NULL;
  else np=t->root;

  while (np!=NULL) {
    int comp=t->compFn(k,np->k);
    if (comp==0) return np;
    else if (comp<0) {
      if (lthread(np)) return NULL;
      else np=np->lt;
    } else {
      if (rthread(np)) return NULL;
      else np=np->rt;
    }
  }
  return NULL;
}

/*************************************************************************/
  static void AVL_FreeNode(np)
/*************************************************************************/
AVL_NODE np;
{
  if (np==NULL) return;
  if (!lthread(np)) AVL_FreeNode(np->lt);
  if (!rthread(np)) AVL_FreeNode(np->rt);
  free((char*)np);
}

/*************************************************************************/
  void AVL_Free(t)
/*************************************************************************/
AVL_TREE t;
{
  AVL_FreeNode(t->root);
  free((char*)t);
}

/*************************************************************************/
  int AVL_UidCmp(a,b)
/*************************************************************************/
AVL_KEY a, b;
{
  return (a.u>b.u) ? 1 : ((a.u<b.u) ? (-1) : 0);
}

/*************************************************************************/
  int AVL_StrCmp(a,b)
/*************************************************************************/
AVL_KEY a, b;
{
  return strcmp(a.s,b.s);
}

/**************************************************************************

  This stuff is an AVL tree dumper which is useful for debugging the
  AVL tree code. It's not really wanted now, even if we have debugging
  turned on because the AVL tree code is pretty solid now.

**************************************************************************/

#ifdef NOTDEF

/*************************************************************************/
  static int  AVL_FindNode(n, t)
/*************************************************************************/
AVL_NODE n;
AVL_TREE t;
{
  AVL_NODE np;
  int count;

  for (count=0, np=AVL_First(t); np!=NULL; np=AVL_Next(np), ++count ) {
    if (n==np) return count;
  }
  return (-1);
}

/*************************************************************************/
  void AVL_Dump(t)
/*************************************************************************/
AVL_TREE t;
{
  AVL_NODE np;
  int n, count;

  fprintf( stderr, "Dumping tree: " );
  if (t->root==NULL) fprintf( stderr, "---\n" );
  else if ((n=AVL_FindNode(t->root,t))==(-1)) fprintf( stderr, "???\n" );
  else fprintf( stderr, "%3.3d\n", n );
  fprintf( stderr, "NODE KEY             LFT RHT B<>LR\n" );

  for (count=0, np=AVL_First(t); np!=NULL; np=AVL_Next(np), ++count) {
    fprintf( stderr, "%3.3d: %-16.16s", count, AVL_Key(np).s );
    if (np->lt==NULL) fprintf( stderr, "--- " );
    else if ((n=AVL_FindNode(np->lt,t))==(-1)) fprintf( stderr, "??? " );
    else fprintf( stderr, "%3.3d ", n );
    if (np->rt==NULL) fprintf( stderr, "--- " );
    else if ((n=AVL_FindNode(np->rt,t))==(-1)) fprintf( stderr, "??? " );
    else fprintf( stderr, "%3.3d ", n );
    fprintf( stderr, np->flags&AVLBALANCED ?   "B" : "." );
    fprintf( stderr, np->flags&AVLLEFTHEAVY ?  "<" : "." );
    fprintf( stderr, np->flags&AVLRIGHTHEAVY ? ">" : "." );
    fprintf( stderr, np->flags&LTHREADBIT ?    "L" : "." );
    fprintf( stderr, np->flags&RTHREADBIT ?    "R" : "." );
    fprintf( stderr, "\n" );
  }
}

#endif /* NOTDEF */
lfu-3.1.5/src/cache.c   644  75362  74430       54531  6510207075   7536 /**************************************************************************

  File caching:

  $Author: paul $
  $Revision: 1.4 $
  $Date: 1998/03/31 15:39:07 $

  Copyright (c) 1992 by the University of Edinburgh
  Laboratory for the Foundations of Computer Science
  Department of Computer Science
  Written by Paul Anderson.

  Permission is granted to anyone to use this software for any
  purpose on any computer system, and to redistribute it freely,
  subject to the following restrictions:

  The University of Edinburgh makes no representations about the
  suitability of this software for any purpose.  It is
  provided "as is" without express or implied warranty.

  The origin of this software must not be misrepresented, either by
  explicit claim or by omission, and this copyright notice must appear in
  all copies of the software. Altered versions must be plainly marked
  as such, and must not be misrepresented as being the original software.

  The name of the University of Edinburgh must not be used in
  advertising or publicity pertaining to distribution of the software
  without specific, written prior permission. 

**************************************************************************/

#define _CACHE_C

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef LFU_CACHE

#include <stdio.h>
#include "misc.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include "avl.h"
#include "eval.h"
#include "stats.h"
#include "tokens.h"
#include "pass2.h"
#include "cache.h"

/*************************************************************************

  (*) Initially, all files listed in the cache file are read into the
      initCache.

  (*) On pass 1 :-

      Files which are unchanged cache links are removed from the initCache
      (if present) and added to the link cache.

      Files which are unchanged cache copies are removed from the initCache
      (if present) and added to the copy cache.

      Files which are deleted are left in the initCache (if present) or
      added to the initCache (if not present).

      In addition, the cache records for all files encountered have their
      cache values updated according to the atime of the file.

  (*) On pass 2 :-

      Any new cache links which are created are removed from the initCache
      (if present) and added to the link cache.

      If there is no room to create cache links (or copies of uncached files)
      then copies are converted into links (in descending cache value order)
      and the corresponding entries moved from the copyCache to the linkCache.

  (*) After pass 2 :-

      Any remaining initCache is deleted to reclaim the memory.
      This should only contain items which have been deleted from the source
      since the last run.

      As many links as possible are converted into copies (in cache value
      order) and the corresponding entries are moved from the linkCache
      to the copyCache.

  (*) Finally, the copyCache and the linkCache are written out to
      form the new cache file.

*************************************************************************/

/*************************************************************************
  Globals
*************************************************************************/

extern int errno;                    /* System error number */
static AVL_TREE initCache;           /* Initial cache read from file */
static AVL_TREE linkCache;           /* Cache of link objects */
static AVL_TREE copyCache;           /* Cache of copied objects */
static time_t lastTime;              /* Time of last cache inspection */
static int maxLevel;                 /* Max level to be decached */

/*************************************************************************/
  static int AVL_CacheCmp(a,b)
/*************************************************************************/
AVL_KEY a, b;
{
  /* If two files have the same cache value, then we order them by
     usage: this gives precedence to the more recently used one.
     If the usage is the same as well, then the smaller file gets
     precedence. If the size is the same as well, we use ordering on the
     name - this is arbitrary but it ensures that things always appear
     in the same order in the cache. */

  return (CacheValue(a.cr)>CacheValue(b.cr)) ? 1 :
    (CacheValue(a.cr)<CacheValue(b.cr)) ? (-1) :
      (a.cr->usage>b.cr->usage) ? 1 :
	(a.cr->usage<b.cr->usage) ? (-1) :
	  (a.cr->size>b.cr->size) ? (-1) :
	    (a.cr->size<b.cr->size) ? 1 :
	      strcmp(a.cr->fname,b.cr->fname);
}

/*************************************************************************/
  static bool UpdateCache( fname, blocks, s, t, ap )
/*************************************************************************/
char *fname;
long blocks;
struct stat *s;
AVL_TREE t;
ACTIONS *ap;
{
  bool accessed;
  AVL_KEY k;
  AVL_VALUE v;
  AVL_NODE np;
  unsigned usage;
  char *name;

  if (!caching) return false;

  accessed=false;
  k.s = name = dstRel(fname);

  /* If it didn't appear in the cache file, we need a new record */
  if ((np=AVL_Lookup(k,initCache)) == NULL) {
    CACHEREC *cp = (CACHEREC*)NewMem(sizeof(*cp));
    cp->fname = NewString(name,NOSTR);
    cp->usage = DEF_USAGE;
    for (cp->level=0, usage=DEF_USAGE; usage!=0; usage>>=1)
      if (usage&1) ++cp->level;
    v.cr = cp;

  /* Otherwise, use the entry from the file */
  } else {
    v=AVL_Value(np);
    AVL_Remove(k,initCache);
  }

  if (t!=initCache) k.cr=v.cr;
  else k.s=(v.cr)->fname;

  /* The timing here is important - we consider a file accessed if the
     atime of the file is more recent than the mtime of the cache itself.
     Because the cache is written out at the end of the lfu run, this means
     that file accesses *during* the lfu run itself do not count. This is
     useful because we don't have to worry about modifying atimes as a 
     side effect of doing things like reading links. */

  if (s) {

    /* Has the file been accessed recently */
    accessed = (s->st_atime>lastTime);

    /* Try to determine whether the file itself has really been accessed,
       or just the link. */
    if (accessed && t==linkCache) {
      struct stat tbuf;
      if (stat(fname,&tbuf) == FAIL) {
	Err( E_STAT, fname, NOSTR );
      } else {
	accessed = (tbuf.st_atime>lastTime);

#ifdef LFU_DEBUG
	if (DebugFlag(D_CACHE) && !accessed)
	  (void)fprintf( stdout, "--: cache: %s (bogus access?)\n", name );
#endif

      }
    }

    /* Update the usage and level and stats */
    if (accessed) {
      if ((v.cr->usage&1)==0) ++v.cr->level;
      v.cr->usage = (1<<(CACHE_HISTORY-1)) | (v.cr->usage>>1);
      if (t==linkCache)	Record( R_CACHEMISS,name,s->st_uid,blocks,ap->flags );
      else Record( R_CACHEHIT,name,s->st_uid,blocks,ap->flags );
    } else {
      if ((v.cr->usage&1)!=0) --v.cr->level;
      v.cr->usage = (v.cr->usage>>1);
      if (t==linkCache) Record( R_CACHELINK,name,s->st_uid,blocks,ap->flags );
      else Record( R_CACHEFILE,name,s->st_uid,blocks,ap->flags );
    }
  }

  v.cr->size = blocks;
  v.cr->act = *ap;
  v.cr->act.flags |= F_INCACHE;

  if ((np=AVL_Add( k, v, t )) == NULL) Fatal( E_MEM, NOSTR, NOSTR );

  return accessed;
}

/*************************************************************************/
  bool CacheChange( fname, blocks, s, ap )
/*************************************************************************/
char *fname;
long blocks;
struct stat *s;
ACTIONS *ap;
{
  return UpdateCache( fname, blocks, s, initCache, ap );
}

/*************************************************************************/
  bool CacheLink( fname, blocks, s, ap )
/*************************************************************************/
char *fname;
long blocks;
struct stat *s;
ACTIONS *ap;
{
  return UpdateCache( fname, blocks, s, linkCache, ap );
}

/*************************************************************************/
  bool CacheCopy( fname, blocks, s, ap )
/*************************************************************************/
char *fname;
long blocks;
struct stat *s;
ACTIONS *ap;
{
  return UpdateCache( fname, blocks, s, copyCache, ap );
}

/*************************************************************************/
  static int WriteEntry( cp, fp )
/*************************************************************************/
CACHEREC *cp;
FILE *fp;
{
  if (cp->usage != DEF_USAGE && strchr(cp->fname,'\n')==NULL) {
    (void)fprintf( fp, "%s %x\n",  cp->fname, cp->usage );
    return 1;
  } else return 0;
}

/*************************************************************************/
  static void WriteCache()
/*************************************************************************/
{
  AVL_NODE np;
  FILE *fp;
  int count=0;
  mode_t mask;

  mask=umask(022);
  if (!(fp=fopen(cacheFile,"w"))) {
    Fatal( E_OPEN, cacheFile, NOSTR );
  }
  umask(mask);

  for (np=AVL_Last(copyCache); np!=NULL; np=AVL_Prev(np)) {
    count += WriteEntry( AVL_Value(np).cr, fp );
  }
  for (np=AVL_Last(linkCache); np!=NULL; np=AVL_Prev(np)) {
    count += WriteEntry( AVL_Value(np).cr, fp );
  }

  /* We need to touch the file to update the mtime if it has no
     records in it. */

  if (count==0) {
    if ((ftruncate(fileno(fp),(off_t)1)==FAIL) ||
	(ftruncate(fileno(fp),(off_t)0)==FAIL)) {
      Fatal( E_TRUNC, cacheFile, NOSTR );
    }
  }
  (void)fclose(fp);
}

/*************************************************************************/
  static void CleanCache()
/*************************************************************************/
{
  AVL_NODE np;

  while (AVL_Size(initCache) != 0) {
    np=AVL_First(initCache);
    AVL_Remove( AVL_Key(np), initCache );
  }
}

/*************************************************************************/
  static void FillCache()
/*************************************************************************/
{
  AVL_NODE np;
  AVL_KEY k;
  AVL_VALUE v;
  char *srcName, *dstName;
  struct stat sbuf, dbuf;
  long maxSpace;
  int fullUp;

  /* This routine works through the cache links in priority order trying to 
     bring the objects into the cache by deleting the links and copying
     the files. The objects are transferred from the linkCache to the
     copyCache as they are processed. */

  /* This is an upper limit on the amount of space left in the destination
     filesystem - (-1) is a dummy value meaning we don't know */
  maxSpace = (-1l);

  fullUp=false; while (AVL_Size(linkCache)!=0 && !fullUp) {

    /* Get highest priority item from the link cache */
    np=AVL_Last(linkCache);
    k=AVL_Key(np); v=AVL_Value(np);

    /* Give up if the priority isn't high enough */
    if (CacheValue(v.cr) < cacheMinValue) break;
    else AVL_Remove( k, linkCache );
    
    /* Get the full names */
    dstName=NewString(theDst, "/", v.cr->fname, NOSTR);
    srcName=NewString(theSrc, "/", v.cr->fname, NOSTR);
    
    /* Get the status of the src & dst */
    if (lstat(srcName,&sbuf) == FAIL) {
      Err( E_STAT, srcName, NOSTR );
    } else if (lstat(dstName,&dbuf) == FAIL) {
      Err( E_STAT, dstName, NOSTR );
      
      /* Only attempt to encache it if it looks like it might fit */

    } else if (maxSpace==(-1l) || StatBlocks(sbuf)<maxSpace) {
      
      Record(R_CACHE,dstName,dbuf.st_uid,StatBlocks(dbuf),v.cr->act.flags);

      /*  Delete the destination */
      if (unlink(dstName) == FAIL) Err( E_UNLNK, dstName, NOSTR );
      
      else {
	
	Record(R_DEL,dstName,dbuf.st_uid,StatBlocks(dbuf),v.cr->act.flags);

	/* Copy the file - never decache anything with a higher priority
	   than this object to make room */

	maxLevel = CacheValue(v.cr);
	if (Copy( srcName,dstName, &sbuf,&(v.cr->act), false )) {

	  /* Set attributes on new destination */
	  if (lstat(dstName,&dbuf) == FAIL) {
	    Err( E_STAT, dstName, NOSTR );
	  } else if (SetAttrs( dstName, &dbuf, &sbuf, &(v.cr->act), false)) {
	    /* Log it as encached */
	    if (v.cr->act.flags&F_LOG)
	      Log( L_ECACHE, v.cr->fname, (char*)CacheValue(v.cr));
	    Record(R_COPY,dstName,sbuf.st_uid,StatBlocks(dbuf),v.cr->act.flags);
	  }

	/* The copy failed for some reason */
	} else {	

	  /* If it failed because there was no room, we want to put the
	     link back. If it failed for some other reason, the error will
	     have been reported and we don't do anything. */

	  if (errno==ENOSPC) {
	    
	    (void)unlink(dstName);

	    maxLevel = MAX_LEVEL;
	    if (Copy( srcName, dstName, &sbuf, &(v.cr->act), true ))
	      Record(R_LINK,dstName,sbuf.st_uid,StatBlocks(dbuf),v.cr->act.flags);

	    if (lstat(dstName,&dbuf) == FAIL)
	      Err( E_STAT, dstName, NOSTR );
	    else {
	    
	      (void)SetAttrs( dstName, &dbuf, &sbuf, &(v.cr->act), false);
	      
	      /* This file didn't fit, so we have a new upper bound
		 on the free space. */
	      
	      maxSpace=StatBlocks(sbuf)-StatBlocks(dbuf);
	      if (maxSpace<0l) maxSpace=0l;
	      
	    }
	    
	    if (v.cr->act.flags&F_LOGALL)
	      Log( L_NCACHE, v.cr->fname, NOSTR );
	    
	    /* If we continue to fill up the cache with smaller things,
	       then the destination will not be "stable". ie. next time
	       the update runs, the small things will all be deleted again
	       to try and make room for the big item. The big item
	       still won't fit, so all the small things will be recopied.
	       Hence, we stop here unless "cachefill" has been specified. */
	    
	    if (!cacheFill) fullUp=true;
	  }
	}
      }
    } else if (v.cr->act.flags&F_LOGALL)
      Log( L_NCACHE, v.cr->fname, NOSTR );
    
    /* Add it to the copy cache */
    if (AVL_Add(k,v,copyCache) == NULL) Fatal( E_MEM, NOSTR, NOSTR );

    free(srcName);
    free(dstName);
  }
}

/*************************************************************************/
  static bool MakeRoom( size )
/*************************************************************************/
long size;
{
  AVL_NODE np;
  AVL_KEY k;
  AVL_VALUE v;
  char *srcName, *dstName;
  struct stat dbuf, sbuf;
  long saving;

  /* This routine is called when we get an error trying to create something
     on the destination. If the error occurred because there was no room,
     then we try to throw some things out of the cache to make room. */

  /* Keep converting copies into links until we have enough room */
  while (size>0l) {

    if (AVL_Size(copyCache)>0) {

      /* Remove lowest priority item from the copy cache */
      np=AVL_First(copyCache);
      k=AVL_Key(np); v=AVL_Value(np);
      
      /* Check priority limits */
      if (CacheValue(v.cr) >= maxLevel) {
	errno= ENOSPC;
	return false;
      }

      AVL_Remove( k, copyCache );
    
      /* Get the full names */
      dstName=NewString(theDst, "/", v.cr->fname, NOSTR);
      srcName=NewString(theSrc, "/", v.cr->fname, NOSTR);
      
      /* Find the size of the existing destination */
      if (lstat(dstName,&dbuf) == FAIL) {
	Err( E_STAT, dstName, NOSTR );
      } else {
	saving = StatBlocks(dbuf);
	
	/* And the status of the source */
	if (lstat(srcName,&sbuf) == FAIL) {
	  Err( E_STAT, srcName, NOSTR );
	  
	  /*  Delete the destination */
	} else if (unlink(dstName) == FAIL) Err( E_UNLNK, dstName, NOSTR );
	
	else {
	  
	  Record(R_DEL,dstName,dbuf.st_uid,StatBlocks(dbuf),v.cr->act.flags);
	  
	  /* Link the file */
	  if (Copy( srcName, dstName, &sbuf, &(v.cr->act), true )) {
	    
	    /* Find the size of the new destination */
	    if (lstat(dstName,&dbuf) == FAIL) {
	      Err( E_STAT, dstName, NOSTR );
	    } else saving -= StatBlocks(dbuf);
	    
	    if (SetAttrs( dstName, &dbuf, &sbuf, &(v.cr->act), false )) {
	      
	      /* Log it as decached */
	      if (v.cr->act.flags&F_LOG)
		Log( L_UCACHE, v.cr->fname, (char*)CacheValue(v.cr)); 
	      Record( R_LINK, dstName, sbuf.st_uid, StatBlocks(dbuf),
		     v.cr->act.flags);
	      
	      /* Add it to the link cache */
	      if (AVL_Add(k,v,linkCache) == NULL) Fatal( E_MEM, NOSTR, NOSTR );
	      
	      /* This is how much room we've made */
	      size -= saving;
	    }
	  }
	}
      }

      free(srcName);
      free(dstName);

    } else { errno=ENOSPC; return false; }
  }
  return true;
}

/*************************************************************************/
  void InitCache( dst )
/*************************************************************************/
char *dst;
{
  char bufr[MAXPATHLEN+33], *p;
  struct stat sbuf;
  FILE *fp;
  unsigned usage;
  unsigned lNo;

  /* Invent a default name for the cache file */
  if (cacheFile==NOSTR) {
    char *p;
    if (cacheDir==NOSTR) cacheDir=CACHE_DIR;
    cacheFile=NewString(cacheDir,CACHE_PFX,dst,NOSTR);
    for ( p=cacheFile+strlen(cacheDir)+strlen(CACHE_PFX);
	  *p!='\0'; ++p) if (*p=='/') *p='.';
  }

  /* Make a separate tree for each cache entry type */
  if ((initCache==NOTREE &&
       (initCache=AVL_NewTree(AVL_StrCmp))==NULL) ||
      (linkCache==NOTREE &&
       (linkCache=AVL_NewTree(AVL_CacheCmp))==NULL) ||
      (copyCache==NOTREE &&
       (copyCache=AVL_NewTree(AVL_CacheCmp))==NULL))
    Fatal( E_MEM, NOSTR, NOSTR );

  /* Don't read the cache file unless we need it */
  if (!caching) {
    (void)time(&lastTime);
    return;
  }

  /* Last time the cache file was written */
  if (stat(cacheFile,&sbuf) == FAIL) {
    if (errno==ENOENT) {
      (void)time(&lastTime);
      return;
    } else Fatal( E_STAT, cacheFile, NOSTR );
  } lastTime = sbuf.st_mtime;

  if (!(fp=fopen(cacheFile,"r"))) Fatal( E_OPEN, cacheFile, NOSTR );

  lNo=0;

  while (fgets(bufr,MAXPATHLEN+32,fp)) {

    CACHEREC *cp = (CACHEREC*)NewMem(sizeof(*cp));
    AVL_KEY k;
    AVL_VALUE v;
    AVL_NODE np;

    ++lNo;

    p=&bufr[strlen(bufr)]; 
    while (p>bufr && p[-1]!=' ') --p;
    if (p<&bufr[2] || (sscanf( p, "%x\n", &usage) != 1)) {
      sprintf( bufr, "%d", lNo );
      Fatal( E_CACHE, cacheFile, bufr );
    } else *--p='\0';

    cp->fname = NewString(bufr,NOSTR);
    cp->usage = usage;
    for (cp->level=0; usage!=0; usage>>=1) if (usage&1) ++cp->level;
    
    k.s = cp->fname;
    v.cr = NOCACHE;

    if ((np=AVL_Add( k, v, initCache )) == NULL)
      Fatal( E_MEM, NOSTR, NOSTR );
    if (AVL_Value(np).cr!=NOCACHE) {
      CACHEREC *ncp=AVL_Value(np).cr;
      ncp->usage |= cp->usage;
      usage=ncp->usage;
      for (ncp->level=0; usage!=0; usage>>=1) if (usage&1) ++ncp->level;
      free(cp->fname);
      free((char*)cp);
    } else AVL_Value(np).cr = cp;
  }
  (void)fclose(fp);

  /* While copying none cached files, we can eject things of any
     priority from the cache */
  maxLevel = MAX_LEVEL;
}

/*************************************************************************/
  void ConvertToBlocks( numblocks, units )
/*************************************************************************/
long *numblocks;
char units;
{
  switch(units) {
  case 'k':
    *numblocks *= (off_t)1024/HSIZE;
    break;
  case 'm':
    *numblocks *= (off_t)1024*((off_t)1024/HSIZE);
    break;
  case 0:
  case 'b':
    break;
  default:
    Fatal( E_SIZE, "Invalid units specified: expected k, b, or m", NOSTR );
  }
  return;
}

/*************************************************************************/
  void CacheOption( tok, arg )
/*************************************************************************/
int tok;
char *arg;
{
  char dummy=0;
  int n;				/* number of things scanf matches */

  switch (tok) {

  case T_CACHEFILE:
    if (cacheFile!=NOSTR) Fatal( E_OPTION, "cachefile", arg );
    else cacheFile=NewString(arg,NOSTR);
    break;

  case T_CACHEMINSIZE:
    n = sscanf( arg, "%ld%c", &cacheMinSize, &dummy );
    if (n < 1 || n > 2)
      Fatal( E_OPTION, "cacheminsize", arg );
    ConvertToBlocks(&cacheMinSize, dummy);
    break;

  case T_CACHEMINFREE:
    n = sscanf( arg, "%ld%c", &cacheMinFree, &dummy );
    if (n < 1 || n > 2)
      Fatal( E_OPTION, "cacheminsize", arg );
    ConvertToBlocks(&cacheMinFree, dummy);
    break;

  case T_CACHEMINVALUE:
    n = sscanf( arg, "%ld%c", &cacheMinValue, &dummy );
    if (n!=1)
      Fatal( E_OPTION, "cacheminvalue", NOSTR );
    break;

  case T_CACHEFILL:
    cacheFill = true;
    break;
   
  default:
    Fatal( E_OPTION, "unknown", arg );
    break;
  }

  caching=true;
}

/*************************************************************************/
  int CacheHardlink( src, dst )
/*************************************************************************/
char *src;
char *dst;
{
  int result=link(src,dst);
  if ((result == FAIL) && (errno==ENOSPC) &&
      (MakeRoom( MINBLOCKS ))) {
    result=link(src,dst);
  }
  return result;
}

/*************************************************************************/
  int CacheSymlink( src, dst )
/*************************************************************************/
char *src;
char *dst;
{
  int result=symlink(src,dst);
  if ((result == FAIL) && (errno==ENOSPC) &&
      (MakeRoom( MINBLOCKS+LINKBLOCKS ))) {
    result=symlink(src,dst);
  }
  return result;
}

/*************************************************************************/
  int CacheMkdir( path, mode )
/*************************************************************************/
char *path;
int mode;
{
  int result=mkdir(path,mode);
  if ((result == FAIL) && (errno==ENOSPC) &&
      (MakeRoom( MINBLOCKS ))) {
    result=mkdir(path,mode);
  }
  return result;
}

/*************************************************************************/
  int CacheMknod( path, mode, dev )
/*************************************************************************/
char *path;
int mode;
int dev;
{
  int result=mknod(path,mode,dev);
  if ((result == FAIL) && (errno==ENOSPC) &&
      (MakeRoom( MINBLOCKS ))) {
    result=mknod(path,mode,dev);
  }
  return result;
}

/*************************************************************************/
  int CacheWrite( fd, buf, size, blocks )
/*************************************************************************/
int fd;
char *buf;
int size;
long blocks;
{
  struct stat sbuf;
  int count=write(fd,buf,size);
  if ((count == FAIL) && (errno==ENOSPC)) {
    if (fstat(fd,&sbuf) != FAIL)  blocks -= StatBlocks(sbuf);
    if (MakeRoom( blocks+1l )) {
      count=write(fd,buf,size);
    }
  }
  return count;
}

/*************************************************************************/
  int CacheOpen( fname, flags, mode )
/*************************************************************************/
char *fname;
int flags;
int mode;
{
  int fd=open(fname,flags,mode);
  if ((fd == FAIL) && (errno==ENOSPC) &&
      (MakeRoom( MINBLOCKS ))) {
    fd=open(fname,flags,mode);
  }
  return fd;
}

/*************************************************************************/
  void ProcessCache()
/*************************************************************************/
{
  CleanCache();
  FillCache();
  WriteCache();
}

#endif /* CACHE */
lfu-3.1.5/src/eval.c   644  75362  74430       52103  6510207076   7414 /**************************************************************************

  Program interpreter.
  Program construction routines used by the parser.

  $Author: paul $
  $Revision: 1.4 $
  $Date: 1998/03/31 15:39:07 $

  Copyright (c) 1992 by the University of Edinburgh
  Laboratory for the Foundations of Computer Science
  Department of Computer Science
  Written by Paul Anderson.

  Permission is granted to anyone to use this software for any
  purpose on any computer system, and to redistribute it freely,
  subject to the following restrictions:

  The University of Edinburgh makes no representations about the
  suitability of this software for any purpose.  It is
  provided "as is" without express or implied warranty.

  The origin of this software must not be misrepresented, either by
  explicit claim or by omission, and this copyright notice must appear in
  all copies of the software. Altered versions must be plainly marked
  as such, and must not be misrepresented as being the original software.

  The name of the University of Edinburgh must not be used in
  advertising or publicity pertaining to distribution of the software
  without specific, written prior permission. 

**************************************************************************/

#define _EVAL_C

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include "misc.h"
#include <string.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <utmp.h>
#include <ctype.h>
#include "avl.h"
#include "eval.h"
#ifdef LFU_CACHE
#include "cache.h"
#endif

#ifdef WTMP_FILE
#define WTMP WTMP_FILE
#else
#ifdef UTMP_FILE
#define WTMP UTMP_FILE
#else
#define WTMP "/var/adm/wtmp"
#endif
#endif

/*************************************************************************/
  static time_t GetBootTime()
/*************************************************************************/
{
  static long bootTime=0l;

  if (bootTime==0l) {

    FILE *fp;
    struct utmp u;

    if (!(fp=fopen( WTMP ,"r" ))) {
      Fatal( E_OPEN, WTMP, NOSTR );
    }
    
    while (fread( (char*)&u, sizeof(u), 1, fp )) {
#ifdef BOOT_MSG
      if (strcmp(u.ut_line,BOOT_MSG)) continue;
#else
      if (strcmp(u.ut_line,"~")) continue;
      if (strcmp(u.ut_name,"reboot")) continue;
#endif
      bootTime = (time_t)u.ut_time;
    }
    (void)fclose(fp);
  
    if (bootTime==0l) {
      Err( E_BOOT, WTMP, NOSTR );
      bootTime=1l;
    }
  } return bootTime;
}

/*************************************************************************/
  static struct stat *NoStatus()
/*************************************************************************/
{
  static struct stat sbuf;
  static bool firstTime=true;

  if (firstTime) {
    sbuf.st_uid=NOBODY;
    sbuf.st_gid=NOGP;
    sbuf.st_mode=0;
    sbuf.st_size=0;
    sbuf.st_mtime=0;
    sbuf.st_atime=0;
#ifdef HAVE_ST_BLOCKS
    sbuf.st_blocks=0;
#endif
    firstTime=false;
  }
  return &sbuf;
}

/*************************************************************************/
  static struct stat *GetStatus( path, newPfx, ap )
/*************************************************************************/
char *path;
char *newPfx;
ACTIONS *ap;
{
  extern int errno;
  int (*statFn)() = (ap->flags&F_FOLLOW) ? stat : lstat;
  static struct stat sbuf;
  char fName[MAXPATHLEN+1], newName[MAXPATHLEN+1], *sPath;

  /* Compute the full source name */
  (void)sprintf( sPath=fName, "%s/%s", theSrc, path );

  /* If there is an explicit path .... */
  if (newPfx!=NOSTR) {

    /* If there is a prefix to be removed, remove it */
    char *oldPfx= &newPfx[1+strlen(newPfx)]; int pfxLen;
    if ( *oldPfx != '\0' ) {
      if (!strncmp(oldPfx, fName, pfxLen=strlen(oldPfx)) &&
	  (fName[pfxLen]=='/')) {
	sPath += pfxLen+1;
      } else { newPfx=theSrc; sPath=path; }
    }

    /* Otherwise, use the relative name */
    else sPath=path;
    
    /* Add the new prefix */
    (void)sprintf( newName, "%s/%s", newPfx, sPath );
    sPath = newName;
  }

#ifdef LFU_DEBUG
  if (DebugFlag(D_PATH))
    (void)fprintf( stdout, "--: path: %s (condition)\n", sPath );
#endif

  if ((*statFn)(sPath, &sbuf) == FAIL) {
    if (errno!=ENOENT) Err( E_STAT, sPath, NOSTR );
    return NoStatus();
  }
  return &sbuf;
}

/*************************************************************************/
  bool Eval(p, fn, path, sbp, a)
/*************************************************************************/
PROG p;
char *fn;
char *path;
struct stat *sbp;
ACTIONS *a;
{
  if (p==NOPROG) return true;
  else switch (p->i) {

  case I_TYPE:
    a->type = p->a.f;
    return true;

  case I_SET:
    a->flags |= p->a.i;
    return true;

  case I_CLR:
    a->flags &= ~p->a.i;
    return true;

#ifdef LFU_CACHE
  case I_CACHE:
    if ((a->priority = p->a.i) > 0) cacheUsed = true;
    return true;
#endif

  case I_SRC:
    a->src = p->a.s;
    a->srcPfx = p->b.s;
    return true;

  case I_EXEC:
    if (p->a.s==NULL) a->cmnds=NULL;
    else {
      STRINGLIST *cp=(STRINGLIST*)NewMem(sizeof(*cp));
      cp->string = p->a.s;
      cp->next = a->cmnds;
      a->cmnds = cp;
    }
    return true;

  case I_PSET:
    a->permSet = p->a.m;
    a->permClr = p->b.m;
    return true;

  case I_MODE: {
    register struct stat *s = (p->c.s) ? GetStatus(path,p->c.s,a) : sbp;
    return ((s->st_mode&p->a.m)==p->a.m &&
	    (s->st_mode&p->b.m)==(mode_t)0);
  }

  case I_AGE: {
    register struct stat *s = (p->c.s) ? GetStatus(path,p->c.s,a) : sbp;

#ifdef LFU_DEBUG
    if (DebugFlag(D_AGE)) {
      if (p->a.tm==p->b.tm) {
	(void)fprintf( stdout, "--: age: %s (%24.24s = ",
		      path, ctime(&(s->st_mtime)) );
	(void)fprintf( stdout, "%24.24s is %s)\n",
		      ctime(&(p->a.tm)),
		      (s->st_mtime==p->a.tm) ? "true" : "false" );
      } else {
	if (p->a.tm!=(time_t)0) {
	  (void)fprintf( stdout, "--: age: %s (%24.24s > ",
			path, ctime(&(s->st_mtime)) );
	  (void)fprintf( stdout, "%24.24s is %s)\n",
			ctime(&(p->a.tm)),
			(s->st_mtime>p->a.tm) ? "true" : "false" );
	}
	if (p->b.tm!=(time_t)0) {
	  (void)fprintf( stdout, "--: age: %s (%24.24s < ",
			path, ctime(&(s->st_mtime)) );
	  (void)fprintf( stdout, "%24.24s is %s)\n",
			ctime(&(p->b.tm)),
			(s->st_mtime<p->b.tm) ? "true" : "false" );
	}
      }
    }
#endif

    if (p->a.tm==p->b.tm) return s->st_mtime==p->a.tm;
    return (p->a.tm==(time_t)0 || s->st_mtime>p->a.tm)
        && (p->b.tm==(time_t)0 || s->st_mtime<p->b.tm);
  }

  case I_ACCESS: {
    register struct stat *s = (p->c.s) ? GetStatus(path,p->c.s,a) : sbp;
    if (p->a.tm==p->b.tm) return s->st_atime==p->a.tm;
    return (p->a.tm==(time_t)0 || s->st_atime>p->a.tm)
        && (p->b.tm==(time_t)0 || s->st_atime<p->b.tm);
  }

  case I_SIZE: {
    register struct stat *s = (p->c.s) ? GetStatus(path,p->c.s,a) : sbp;
    if (p->a.sz==p->b.sz) return s->st_size==p->a.sz;
    return (p->a.sz==(off_t)0 || s->st_size>p->a.sz)
        && (p->b.sz==(off_t)0 || s->st_size<p->b.sz);
  }

  case I_CHGRP:
    a->group = p->a.g;
    return true;

  case I_AUTO:
    a->srcSubs = p->a.sl;
    a->dstSubs = p->b.sl;
    return true;

  case I_ERROR:
    a->errMsg = p->a.s;
    return true;

  case I_WARN:
    a->warnMsg = p->a.s;
    return true;

  case I_CHOWN:
    a->owner = p->a.u;
    return true;

  case I_NOT:
    return !Eval(p->a.p, fn, path, sbp, a);

  case I_SEQ:
    (void)Eval(p->a.p, fn, path, sbp, a);
    return Eval(p->b.p, fn, path, sbp, a);

  case I_COND:
    if (Eval(p->a.p, fn, path, sbp, a)) return(Eval(p->b.p, fn, path, sbp, a));
    else return (Eval(p->c.p, fn, path, sbp, a));

  case I_AND:
    return (Eval(p->a.p, fn, path, sbp, a) && Eval(p->b.p, fn, path, sbp, a));

  case I_OR:
    return (Eval(p->a.p, fn, path, sbp, a) || Eval(p->b.p, fn, path, sbp, a));

  case I_OWNER: {
    register struct stat *s = (p->c.s) ? GetStatus(path,p->c.s,a) : sbp;
    return (p->a.u==s->st_uid);
  }

  case I_GROUP: {
    register struct stat *s = (p->c.s) ? GetStatus(path,p->c.s,a) : sbp;
    return (p->a.g==s->st_gid);
  }

  case I_NETGRP: {
    AVL_KEY k;
    register struct stat *s = (p->c.s) ? GetStatus(path,p->c.s,a) : sbp;
    k.u = s->st_uid;
    return AVL_Lookup(k, p->a.t) != NULL;
  }

  case I_FILE:
    return regexec(p->a.r, fn);

  case I_PATH:
    return regexec(p->a.r, path);

  case I_NSET: {
    AVL_KEY k;
    k.s = fn;
    return AVL_Lookup(k, p->a.t) != NULL;
  }

  case I_FSET: {
    AVL_KEY k;
    k.s = path;
    return AVL_Lookup(k, p->a.t) != NULL;
  }

  case I_TTEST: {
    register struct stat *s = (p->c.s) ? GetStatus(path,p->c.s,a) : sbp;
    return ((s->st_mode&S_IFMT) == p->a.m);
  }

  default:
    Fatal( E_OPTYPE, p->a.s, NOSTR );
  }
  
  /*NOTREACHED*/
}

/*************************************************************************/
  void EvalDefault( p )
/*************************************************************************/
PROG p;
{
  (void)Eval( p, "", "", NoStatus(), &defAction );
}

/*************************************************************************/
  PROG NewOp(i, a, b, c)
/*************************************************************************/
icode i;
ARG a, b, c;
{
  register PROG ip=(PROG)NewMem(sizeof *ip);
  ip->i=i;
  ip->a=a;
  ip->b=b;
  ip->c=c;
  return ip;
}

/*************************************************************************/
  PROG New1Op(i, ap)
/*************************************************************************/
icode i;
PROG ap;
{
  ARG a;
  a.p=ap;
  return NewOp(i, a, unused, unused);
}

/*************************************************************************/
  PROG New2Op(i, ap, bp)
/*************************************************************************/
icode i;
PROG ap, bp;
{
  ARG a,b;
  a.p=ap;
  b.p=bp;
  return NewOp(i, a, b, unused);
}

/*************************************************************************/
  PROG New3Op(i, ap, bp, cp)
/*************************************************************************/
icode i;
PROG ap, bp, cp;
{
  ARG a,b,c;
  a.p=ap;
  b.p=bp;
  c.p=cp;
  return NewOp(i, a, b, c);
}

/*************************************************************************/
  PROG NewStringOp(i, s, t)
/*************************************************************************/
icode i;
char *s,*t;
{
  ARG a,b;
  a.s=s;
  b.s=t;
  return NewOp(i, a, b, unused);
}

/*************************************************************************/
  PROG NewFTypeOp(i, f)
/*************************************************************************/
icode i;
filetype f;
{
  ARG a;
  a.f=f;
  return NewOp(i, a, unused, unused);
}

/*************************************************************************/
  PROG NewIntOp(i, n)
/*************************************************************************/
icode i;
int n;
{
  ARG a;
  a.i=n;
  return NewOp(i, a, unused, unused);
}

/*************************************************************************/
  static PROG NewNetGroupOp(s, dir)
/*************************************************************************/
char *s;
char *dir;
{
  struct unode { char *name; struct unode *next; } *up = (struct unode*)0, *p;
  char *machine, *user, *domain;
  char bufr[MAXPATHLEN+1];
  FILE *fp;
  ARG a, b, c;
  int count=0;

#ifdef HAVE_GETNETGRENT
  extern int getnetgrent();
  extern int setnetgrent();
  extern int endnetgrent();
#endif

  /* We make a list of the group members before looking up the uids,
     because there seems to be some kind of unwanted interaction
     between the getnetgrent and getpwnam calls. */

#ifndef HAVE_GETNETGRENT
  Fatal( E_UNSUP, "netgroup", s );
#else 

  if ((a.t=AVL_NewTree(AVL_UidCmp))==NULL)  Fatal( E_MEM, NOSTR, NOSTR );

  while (isspace(*s)) ++s;
  if (*s=='\0') Fatal( E_MISSING, "netgroup", "@" );

  if (*s=='/') {

    if (!(fp=fopen(s,"r"))) Fatal( E_OPEN, s, NOSTR );

    while (fgets(bufr,MAXPATHLEN,fp)) {
      if (bufr[0]=='#') continue;
      for (user= &bufr[strlen(bufr)]; user>bufr && isspace(user[-1]); --user);
      user[0]='\0';
      for (user= &bufr[0]; isspace(user[0]); ++user);
      if (user[0]=='\0') continue;
      ++count;
      p=(struct unode*)NewMem(sizeof *p);
      p->name=NewString(user,NOSTR);
      p->next=up;
      up=p;
    }
    (void)fclose(fp);

  } else {

    setnetgrent(s);

    while (getnetgrent(&machine, &user, &domain)) {
      if (user==NOSTR) Fatal( E_UNIGRP, s, NOSTR );
      ++count;
      if (!strcmp(user,"-")) continue;
      if (domain!=NOSTR && domainName!=NOSTR &&
	  strcmp(domain,domainName)) continue;
      p=(struct unode*)NewMem(sizeof *p);
      p->name=NewString(user,NOSTR);
      p->next=up;
      up=p;
    }
    endnetgrent();
  }

  if (count==0) Warn( E_MTGRP, s, NOSTR );

  while (up) {
    struct passwd *pwd;
    if ((pwd=getpwnam(up->name))==NULL) {
      Err( E_MEMBER, up->name, s );
    } else {
      AVL_KEY k;
      AVL_VALUE v;
      k.u = pwd->pw_uid;
      v.s = up->name;
      if (AVL_Add(k, v, a.t)==NULL)
	Fatal( E_MEM, NOSTR, NOSTR );
    }
    p=up->next;
    free((char*)up);
    up=p;
  }
  
  c.s = dir;
  b.s = NewString(s,NOSTR);

  return NewOp(I_NETGRP, a, b, c);

#endif
}

/*************************************************************************/
  PROG NewOwnerOp(s, typ, dir)
/*************************************************************************/
char *s;
icode typ;
char *dir;
{
  struct passwd *pwd;
  ARG a, b, c;
  char *pzt;

  if (typ==I_OWNER && *s=='@') return NewNetGroupOp(s+1, dir);
  if (s==NOSTR) a.u = NOBODY;
  else if ((pwd=getpwnam(s))!=NULL) a.u=pwd->pw_uid;
  else {
    for (pzt=s; *pzt ; pzt++) {
      if (!(isdigit(*pzt))) {
	Fatal( E_USER, s, NOSTR );
      }
    }
    a.u=(uid_t) strtol(s, (char**)NULL, 0);
  }
  b.s = s;
  c.s = dir;
  return NewOp(typ, a, b, c);
}

/*************************************************************************/
  PROG NewGroupOp(s, typ, dir)
/*************************************************************************/
char *s;
icode typ;
char *dir;
{
  struct group *gp;
  ARG a, b, c;

  if (s==NOSTR) a.g = NOGP;
  else if ((gp=getgrnam(s))!=NULL) a.g=gp->gr_gid;
  else Fatal( E_GROUP, s, NOSTR );
  b.s = s;
  c.s = dir;
  return NewOp(typ, a, b, c);
}

/*************************************************************************/
  PROG NewAutoOp(s)
/*************************************************************************/
char *s;
{
  ARG a, b;
  char *dir, *src, *dst;
  STRINGLIST *sp;

  a.sl=NULL;
  b.sl=NULL;

  if (s) {
    while (*s==' ' || *s==',') ++s;
    if (*s!='/') {
      src = strtok(s,"/");
      dst = src ? strtok(NULL,"/") : NOSTR;
    } else src=NOSTR, dst=strtok(s,"/");
  } else src=dst=NOSTR;

  for (dir=src?strtok(src," ,"):NOSTR; dir!=NOSTR; dir=strtok(NULL,", ")) {
    sp=(STRINGLIST*)NewMem(sizeof(*sp));
    sp->string=NewString(dir,NOSTR);
    sp->next=a.sl;
    a.sl=sp;
  }

  for (dir=dst?strtok(dst," ,"):NOSTR; dir!=NOSTR; dir=strtok(NULL,", ")) {
    sp=(STRINGLIST*)NewMem(sizeof(*sp));
    sp->string=NewString(dir,NOSTR);
    sp->next=b.sl;
    b.sl=sp;
  }

  return NewOp(I_AUTO, a, b, unused);
}

/*************************************************************************/
  PROG NewPermOp(str, typ, dir)
/*************************************************************************/
char *str;
icode typ;
char *dir;
{
  bool lhs;
  ARG set, clr, c;
  mode_t mask, *bp;
  char *p;

  lhs = true;
  set.m = (mode_t)0;
  clr.m = (mode_t)0;
  mask = 0;

  if (str!=NOSTR) for (p=str; *p; ++p) {

    if (lhs) {

      switch (*p) {
      case 'u': mask |= S_IRWXU; break;
      case 'g': mask |= S_IRWXG; break;
      case 'o': mask |= S_IRWXO; break;
      case '+': bp = &(set.m); lhs=false; break;
      case '-': bp = &(clr.m); lhs=false; break;
      default: Fatal( E_PSYNT, str, NOSTR );
      }
      
    } else {
      
      if (mask==0) mask=S_IRWXU|S_IRWXG|S_IRWXO;

      switch (*p) {
      case 'r': *bp |= (mask&(S_IRUSR|S_IRGRP|S_IROTH)); break;
      case 'w': *bp |= (mask&(S_IWUSR|S_IWGRP|S_IWOTH)); break;
      case 'x': *bp |= (mask&(S_IXUSR|S_IXGRP|S_IXOTH)); break;
      case 't': *bp |= S_ISVTX; break;
      case 's':
	if (mask&S_IRWXU) *bp |= S_ISUID;
	if (mask&S_IRWXG) *bp |= S_ISGID;
	break;
      case ' ': case ',': mask=0; lhs=true; break;
      default: Fatal( E_PSYNT, str, NOSTR );
      }
    }
  }

  if (lhs) Fatal( E_PSYNT, str, NOSTR );

  c.s = dir; return NewOp(typ, set, clr, c);
}

/*************************************************************************/
  PROG NewTypeOp(str, dir)
/*************************************************************************/
char *str;
char *dir;
{
  static struct modelist { char *name; mode_t m; } mlist[] = {
    { "dir",  S_IFDIR },
    { "file", S_IFREG },
    { "bdev", S_IFBLK },
    { "cdev", S_IFCHR },
#ifdef S_IFSOCK
    { "sock", S_IFSOCK },
#endif
    { "pipe", S_IFIFO },
    { "link", S_IFLNK },
    { "missing", 0 },
    { NULL, 0 },
  };

  ARG a,c;
  struct modelist *mp;

  for ( mp=mlist; mp->name!=NULL; ++mp ) {
    if (!strcmp(str, mp->name)) {
      a.m = mp->m;
      c.s = dir;
      return NewOp( I_TTEST, a, unused, c );
    }
  }
  Fatal( E_TSYNT, str, NOSTR );
  /*NOTREACHED*/
}

/*************************************************************************/
  static PROG NewListOp(fname, typ)
/*************************************************************************/
char *fname;
icode typ;
{
  char bufr[MAXPATHLEN+1], *s;
  FILE *fp;
  ARG a, b;

  while (isspace(*fname)) ++fname;
  if (*fname=='\0') Fatal( E_MISSING, "file", "@" );

  if ((a.t=AVL_NewTree(AVL_StrCmp))==NULL) Fatal( E_MEM, NOSTR, NOSTR );
  else if (!(fp=fopen(fname,"r"))) Fatal( E_OPEN, fname, NOSTR );

  while (fgets(bufr,MAXPATHLEN,fp)) {
    AVL_KEY k;
    AVL_VALUE v;
    if (bufr[0]=='#') continue;
    for (s= &bufr[strlen(bufr)]; s>bufr && isspace(s[-1]); --s);
    s[0]='\0';
    for (s= &bufr[0]; isspace(s[0]); ++s);
    if (s[0]=='\0') continue;
    k.s = NewString(s,NOSTR);
    v.s = NOSTR;
    if (AVL_Add(k, v, a.t)==NULL) Fatal( E_MEM, NOSTR, NOSTR );
  }

  b.s = NewString(fname,NOSTR);

  return NewOp(typ, a, b, unused);
}

/*************************************************************************/
  PROG NewFileOp(s, typ)
/*************************************************************************/
char *s;
icode typ;
{
  ARG a,b;

  if (typ==I_FILE && *s=='@') return NewListOp(s+1, I_NSET);
  else if (typ==I_PATH && *s=='@') return NewListOp(s+1, I_FSET);

  a.r = regcomp(s);
  b.s = NewString(s,NOSTR);
  return NewOp(typ, a, b, unused);
}

/*************************************************************************/
  PROG NewAgeOp(age, older, typ, dir)
/*************************************************************************/
char *age;
int older;
icode typ;
char *dir;
{
  char *p;
  time_t n, tim;
  ARG max, min, c;

  /* If the arg is NULL, then we default to system reboot time */
  if (age==NULL) tim = GetBootTime();

  /* If it starts with a digit it must be a time spec */
  else if (isdigit(*age)) {
    for (n=(time_t)0, p=age; isdigit(*p); ++p) {
      n = (time_t)10*n + (time_t)(*p-'0'); 
    }
    while (isspace(*p)) ++p;

    if (*p=='\0' || !strcmp(p,"mins")) n *= (time_t)60;
    else if (!strcmp(p,"hrs")) n *= (time_t)60*(time_t)60;
    else if (!strcmp(p,"days")) n *= (time_t)60*(time_t)60*(time_t)24;
    else if (!strcmp(p,"wks")) n *= (time_t)60*(time_t)60*(time_t)24*(time_t)7;
    else Fatal( E_AGE, age, NOSTR );

    tim = time(NULL)-n;

  /* Otherwise it must be a filename */
  } else {
    struct stat sbuf;
    if (stat(age, &sbuf) == FAIL) Fatal( E_STAT, age, NOSTR );
    tim = sbuf.st_mtime;
  }

  max.tm = (older>=0) ? tim : (time_t)0;
  min.tm = (older<=0) ? tim : (time_t)0;

  c.s=dir; return NewOp(typ, min, max, c);
}

/*************************************************************************/
  PROG NewSizeOp(size, bigger, dir)
/*************************************************************************/
char *size;
int bigger;
char *dir;
{
  char *p;
  off_t n;
  ARG max, min, c;

  if (isdigit(*size)) {
    for (n=(off_t)0, p=size; isdigit(*p); ++p) {
      n = (off_t)10*n + (off_t)(*p-'0'); 
    }
    while (isspace(*p)) ++p;

    if (*p=='\0') /*EMPTY*/ /* default size is bytes */ ;
    else if (!strcmp(p,"k")) n *= (off_t)1024;
    else if (!strcmp(p,"b")) n *= (off_t)512;
    else if (!strcmp(p,"m")) n *= (off_t)1024*(off_t)1024;

    else Fatal( E_SIZE, size, NOSTR );

  } else Fatal( E_SIZE, size, NOSTR );

  min.sz = (bigger>=0) ? n : (off_t)0;
  max.sz = (bigger<=0) ? n : (off_t)0;

  c.s=dir; return NewOp(I_SIZE, min, max, c);
}

#ifdef LFU_CACHE
/*************************************************************************/
  PROG NewCacheOp( prio )
/*************************************************************************/
char *prio;
{
  ARG a;
  char *p;

  caching=true;

  if (prio==NOSTR) a.i=0;
  else {
    if (isdigit(*prio)) {
      for (a.i=0, p=prio; isdigit(*p); ++p) {
	a.i = 10*a.i + (*p-'0'); 
      }
      while (isspace(*p)) ++p;
      
      if (*p!='\0') Fatal( E_CPRIO, prio, NOSTR );
      
    } else Fatal( E_CPRIO, prio, NOSTR );
    
    if (a.i>MAX_PRIORITY) Fatal( E_CPRIO, prio, NOSTR );
    else ++a.i; /* Internally, the minimum value is 1 */
  }

  return NewOp(I_CACHE, a, unused, unused);
}
#endif

/*************************************************************************/
  void regerror(str)
/*************************************************************************/
char *str;
{
  Fatal( E_REGEXP, str, NOSTR );
}
lfu-3.1.5/src/lfu.c   644  75362  74430       22023  6510207077   7252 /**************************************************************************

  Main program.

  $Author: paul $
  $Revision: 1.4 $
  $Date: 1998/03/31 15:39:07 $

  Copyright (c) 1992 by the University of Edinburgh
  Laboratory for the Foundations of Computer Science
  Department of Computer Science
  Written by Paul Anderson.

  Permission is granted to anyone to use this software for any
  purpose on any computer system, and to redistribute it freely,
  subject to the following restrictions:

  The University of Edinburgh makes no representations about the
  suitability of this software for any purpose.  It is
  provided "as is" without express or implied warranty.

  The origin of this software must not be misrepresented, either by
  explicit claim or by omission, and this copyright notice must appear in
  all copies of the software. Altered versions must be plainly marked
  as such, and must not be misrepresented as being the original software.

  The name of the University of Edinburgh must not be used in
  advertising or publicity pertaining to distribution of the software
  without specific, written prior permission. 
 
**************************************************************************/

#define _LFU_C

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include "misc.h"
#include "mon.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_RPCSVC_YPCLNT_H
#include <rpcsvc/ypclnt.h>
#endif
#include "eval.h"
#include "parse.h"
#include "pass1.h"
#include "pass2.h"
#include "stats.h"
#include "avl.h"

#ifdef LFU_CACHE
#include "cache.h"
#endif

/**************************************************************************
  Externals
**************************************************************************/

extern char *getenv();
extern char *optarg;
extern int optind;

/*************************************************************************/
  static void ShowVersion()
/*************************************************************************/
{
  int i;

  (void)fprintf( stderr, "%s: version %s (options: ", progName, VERSION );

#ifdef HAVE_AMD
  (void)fprintf( stderr, "a" );
#endif
#ifdef LFU_CACHE
  (void)fprintf( stderr, "c" );
#endif
#ifdef LFU_DEBUG
  (void)fprintf( stderr, "d" );
#endif
#ifdef HAVE_GETNETGRENT
  (void)fprintf( stderr, "n" );
#endif
  (void)fprintf( stderr, ") for %s\n", ARCH );

  fprintf( stderr, "preprocessor: %s", cpp );
  for (i=1; i<cppArgc; ++i) fprintf( stderr, " %s", cppArgv[i] );
  fprintf( stderr, "\n" );

  fprintf( stderr, "monitor: %s\n", MONITOR_PROG );

  fprintf( stderr, "current directory: %s\n", FullName(NOSTR) );

  if (domainName==NOSTR) fprintf( stderr, "domain name unknown\n" );
  else fprintf( stderr, "domain: %s\n", domainName );

  exit(0);
}

#ifdef LFU_DEBUG

/*************************************************************************/
  static void DebugOption(s)
/*************************************************************************/
char *s;
{
  char *p;

  static struct _debugOpt {
    char *opt;
    int flag;
  } options[] = {
    { "parse",  D_PARSE, },
    { "input",  D_INPUT, },
    { "line",   D_LINE, },
    { "cache",  D_CACHE, },
    { "scan",   D_SCAN, },
    { "path",   D_PATH, },
    { "age",    D_AGE },
    { NOSTR,    0 },
  }, *o;

  for ( p=strtok(s," ,:"); p!=NULL; p=strtok(NULL," ,:") ) {
    for ( o=options; o->opt!=NOSTR; ++o ) if (!strcmp(p,o->opt)) break;
    if (o->flag) {
      debugFlags |= o->flag;
    } else {
      Fatal( E_DEBUG, p, NOSTR );
    }
  }
}

#endif

/*************************************************************************/
  static void Usage()
/*************************************************************************/
{
  (void)fprintf( stderr, "Usage: %s [opts] [prog-file] src dst\n", progName );
#ifdef HAVE_AMD
  (void)fprintf( stderr, "  -a      Do not resolve pathnames with AMD\n" );
#endif
#ifdef LFU_CACHE
  (void)fprintf( stderr, "  -A <D>  Use directory <D> for cache data files\n" );
#endif
  (void)fprintf( stderr, "  -c      Monitor progress\n" );
  (void)fprintf( stderr, "  -C      Don't compare symlink contents\n" );
  (void)fprintf( stderr, "  -d <D>  Use domain name <D>\n" );
  (void)fprintf( stderr, "  -D <S>  Option for preprocessor\n" );
  (void)fprintf( stderr, "  -e <E>  Use program expression <E>\n" );
  (void)fprintf( stderr, "  -f      Force updates\n" );
#ifdef HAVE_CLUSTER_H
  (void)fprintf( stderr, "  -H      Copy CDFs\n" );
#endif
  (void)fprintf( stderr, "  -I <S>  Option for preprocessor\n" );
  (void)fprintf( stderr, "  -l      Link files\n" );
  (void)fprintf( stderr, "  -m      Do not cross mount points\n" );
  (void)fprintf( stderr, "  -o      Change owner/group to current user\n" );
  (void)fprintf( stderr, "  -p      Preserve files\n" );
  (void)fprintf( stderr, "  -P <P>  Use preprocessor <P>\n" );
  (void)fprintf( stderr, "  -r      Report all errors\n" );
  (void)fprintf( stderr, "  -s      Collect stats\n" );
  (void)fprintf( stderr, "  -S      Print memory and time statistics\n" );
  (void)fprintf( stderr, "  -v      Log all changes\n" );
  (void)fprintf( stderr, "  -V      Display version number\n" );
  (void)fprintf( stderr, "  -w      Print warnings\n" );
#ifdef LFU_DEBUG
  (void)fprintf( stderr, "  -X <F>  Set debug flags <F>\n" );
#endif
  exit(1);
}

/*************************************************************************/
  main(argc, argv)
/*************************************************************************/
int argc;
char *argv[];
{
  int c;
  PROG prog;
  char *src, *dst;

  InitMonitor();

  progName = BaseName(argv[0]);
  domainName = NOSTR;

#ifdef LFU_CACHE
  caching = false;
  cacheUsed = false;
  cacheMinSize = CACHE_MIN_SIZE;
  cacheMinValue = CACHE_MIN_VALUE;
  cacheMinFree = CACHE_MIN_FREE;
  cacheFill = false;
  cacheDir=NOSTR;
#endif /* CACHE */

  prog = NOPROG;
  errCount = 0;

#ifdef LFU_DEBUG
  debugFlags=0;
#endif

  optm = false;
  opta = false;
  optC = false;
  optc = false;
  optV = false;
  optS = false;
  optw = false;

  defAction.type = A_UPDATE;
  defAction.flags = 0;
  defAction.permSet = 0;
  defAction.permClr = 0;
  defAction.cmnds = NULL;
  defAction.srcSubs = NULL;
  defAction.dstSubs = NULL;
  defAction.owner = NOBODY;
  defAction.group = NOGP;
  defAction.errMsg = NOSTR;
  defAction.warnMsg = NOSTR;
  defAction.src = NOSTR;
  defAction.srcPfx = NOSTR;
#ifdef LFU_CACHE
  defAction.priority = 0;
#endif

  cppOpt=CPP_PATH;
  cppArgc=1;

  while ((c=getopt(argc, argv, "A:X:P:e:d:D:I:lfvorcamHpVCsSw")) != -1) {
    switch (c) {

    case 'P':
      cppOpt = NewString( optarg, NOSTR );
      break;

#ifdef LFU_CACHE
    case 'A':
      cacheDir = NewString( optarg, NOSTR );
      break;
#endif

    case 'e':
      prog=ParseString(prog, optarg);
      break;

    case 'd':
      if (domainName!=NOSTR) Usage();
      else domainName = optarg;
      break;

    case 'D':
      if (cppArgc>=MAXCPPARGS) Fatal( E_ARGS, NOSTR, NOSTR );
      cppArgv[cppArgc++] = NewString( "-D", optarg, NOSTR) ;
      break;

    case 'I':
      if (cppArgc>=MAXCPPARGS) Fatal( E_ARGS, NOSTR, NOSTR );
      cppArgv[cppArgc++] = NewString( "-I", optarg, NOSTR) ;
      break;

    case 'l':
      defAction.flags |= F_SHADOW;
      break;

    case 'f':
      defAction.flags |= F_FORCE;
      break;

    case 'v':
      defAction.flags |= F_LOG;
      break;

    case 'p':
      defAction.type = A_PRESERVE;
      break;

    case 'o':
      defAction.owner = geteuid();
      defAction.group = getegid();
      break;

#ifdef LFU_DEBUG
    case 'X':
      DebugOption(optarg);
      break;
#endif

    case 'm':
      optm = true;
      break;

    case 'r':
      optr = true;
      break;

    case 'w':
      optw = true;
      break;

#ifdef HAVE_AMD
    case 'a':
      opta = true;
      break;
#endif

    case 'c':
      optc = true;
      break;

    case 'C':
      optC = true;
      break;

#ifdef HAVE_CLUSTER_H
    case 'H':
      defAction.flags |= F_CDF;
      break;
#endif

    case 's':
      defAction.flags |= F_STATS;
      break;

    case 'S':
      optS = true;
      break;

    case 'V':
      optV=true;
      break;

    default:
      Usage();
    }
  }

  FindCPP( cppOpt );

  if (domainName==NOSTR) {
#ifdef HAVE_GETNETGRENT
    domainName=getenv("LOCALDOMAIN");
#ifdef HAVE_YP_GET_DEFAULT_DOMAIN
    if (domainName==NOSTR) {
      int status;
      if ((status=yp_get_default_domain(&domainName))!=0) {
	if (status==YPERR_NODOM) domainName=NOSTR;
	else Fatal( E_DOMAIN, (char*)yperr_string(status), NOSTR );
      }
    }
#endif
#endif
  }
  if (domainName!=NOSTR && *domainName=='\0') domainName=NOSTR;

  if (optV) ShowVersion();

  if (argc-optind == 3) prog=ParseFile(prog, argv[optind++]);

#ifdef LFU_DEBUG
  if (DebugFlag(D_PARSE)) exit(0);
#endif

  if (argc-optind != 2) Usage();
  src = FullName(argv[optind++]);
  dst = FullName(argv[optind++]);

  (void)umask(0);

#ifdef LFU_CACHE
  InitCache(dst);
#endif

  Pass1( src, dst, prog, &defAction );
  Pass2( src, dst, prog, &defAction );

#ifdef LFU_CACHE
  if (caching) ProcessCache();
#endif

  CloseMonitor();
  ShowStats();

  exit( errCount?2:0 );

  /*NOTREACHED*/
  return errCount?2:0;
}
lfu-3.1.5/src/misc.c   644  75362  74430       51255  6514420221   7420 /**************************************************************************

  Miscellaneous routines.

  $Author: paul $
  $Revision: 1.4 $
  $Date: 1998/03/31 15:39:07 $

  Copyright (c) 1992 by the University of Edinburgh
  Laboratory for the Foundations of Computer Science
  Department of Computer Science
  Written by Paul Anderson.

  Permission is granted to anyone to use this software for any
  purpose on any computer system, and to redistribute it freely,
  subject to the following restrictions:

  The University of Edinburgh makes no representations about the
  suitability of this software for any purpose.  It is
  provided "as is" without express or implied warranty.

  The origin of this software must not be misrepresented, either by
  explicit claim or by omission, and this copyright notice must appear in
  all copies of the software. Altered versions must be plainly marked
  as such, and must not be misrepresented as being the original software.

  The name of the University of Edinburgh must not be used in
  advertising or publicity pertaining to distribution of the software
  without specific, written prior permission. 
 
**************************************************************************/

#define _MISC_C

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include "misc.h"
#include <sys/file.h>
#include <varargs.h>
#include <signal.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/wait.h>

#include "stats.h"
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#else
extern char *malloc();
#endif
#ifdef HAVE_VFORK_H
#include <vfork.h>
#endif

#ifndef HAVE_GETWD
extern char *getcwd();
#else
extern char *getwd();
#endif

#ifdef HAVE_AMD
extern char *getawd();
#endif

/**************************************************************************
  Globals
**************************************************************************/

static int execPid;                  /* PID of subprocess for exec */

extern int errno;
#ifndef HAVE_SYS_ERRLIST
extern char *sys_errlist[];
#endif

/*************************************************************************/
  unsigned long *NewMem( bytes )
/*************************************************************************/
int bytes;
{
  unsigned long *p = (unsigned long*)malloc(bytes);
  if (p==(unsigned long*)0) Fatal( E_MEM, NOSTR, NOSTR );
  return p;
}

/*************************************************************************/
  /*VARARGS*/ char *NewString( va_alist )
/*************************************************************************/
va_dcl
{
  va_list ap;
  char *s, *p;
  int len=0;

  va_start(ap);
  while ( (s=va_arg(ap, char*)) != NOSTR ) len += strlen(s);
  va_end(ap);

  s = p = (char*)NewMem(1+len); *p='\0';
  va_start(ap);
  while ( (s=va_arg(ap, char*)) != NOSTR ) (void)strcat( p, s );
  va_end(ap);

  return p;
}

/*************************************************************************/
  char *BaseName(s)
/*************************************************************************/
char *s;
{
  register char *t;

  for ( t= &s[strlen(s)]; t!=s && *t!='/'; --t );
  if (*t=='/') ++t;
  return t;
}

/*************************************************************************/
  char *FullName(s)
/*************************************************************************/
char *s;
{
  static char *cwd=NOSTR;
  char *f,*p,*t,*fn;

  if (cwd==NULL) {
    cwd=(char*)NewMem(MAXPATHLEN+1);
#ifdef HAVE_AMD
    if (!opta) {
      if (getawd(cwd)==NULL) Fatal( E_CWD, NOSTR, NOSTR );
    } else
#endif
#ifndef HAVE_GETWD
    if (getcwd(cwd,MAXPATHLEN+1)==NULL) Fatal( E_CWD, NOSTR, NOSTR );
#else
    if (getwd(cwd)==NULL) Fatal( E_CWD, NOSTR, NOSTR );
#endif
  }

  /* Make a full pathname */
  if (s==NOSTR) f=NewString(cwd,NOSTR);
  else if (s[0]=='/') f=NewString(s,NOSTR);
  else f=NewString(cwd,"/",s,NOSTR);

  /* Remove any "." and ".." components */
  fn=NewString("",NOSTR);
  for ( p=strtok(f+1,"/"); p!=NULL; p=strtok(NOSTR,"/") ) {
    if ((*p=='\0') || !strcmp(p,".")) continue;
    else if (!strcmp(p,"..")) {
      t= &fn[strlen(fn)]; while (t>fn && *t!='/') --t; *t='\0';
    } else {
      t=NewString(fn,"/",p,NOSTR); free(fn); fn=t;
    }
  } free(f);

  if (*fn=='\0') { free(fn); return NewString("/",NOSTR); }
  return fn;
}

/*************************************************************************/
  void FindCPP( cppName )
/*************************************************************************/
char *cppName;
{
  char *cppl, *args;

  cppl = NewString( cppName, NOSTR );
  for (cpp=strtok(cppl,":"); cpp!=NOSTR; cpp=strtok(NOSTR,":")) {
    if ((args=strchr(cpp,','))!=NOSTR) *args++='\0';
    if (access(cpp,X_OK)==0) break;
  }
  if (cpp==NOSTR) Fatal( E_CPP, cppName, NOSTR );

  cppArgv[0] = BaseName(cpp);

  if (args) {
    for (args=strtok(args,","); args!=NOSTR; args=strtok(NOSTR,",")) {
      if (cppArgc>=MAXCPPARGS) Fatal( E_ARGS, NOSTR, NOSTR );
      else cppArgv[cppArgc++] = args;
    }
  }
}

/*************************************************************************/
  FILE *ExecCPP( fname )
/*************************************************************************/
char *fname;
{
  int p[2];
  FILE *fp;

  if (cppArgc>=MAXCPPARGS) Fatal( E_ARGS, NOSTR, NOSTR );
  else cppArgv[cppArgc++] = fname;

  cppArgv[cppArgc] = NOSTR;

  if (pipe(p)<0) Fatal( E_PIPE, NOSTR, NOSTR );

  if ((execPid = vfork()) == 0) {
    (void)close(p[0]);
    (void)dup2(p[1],1);
    (void)close(p[1]);
    (void)execv( cpp, cppArgv );
    _exit(127);
  }

  if (execPid == FAIL) Fatal( E_FORK, cpp, NOSTR );

  (void)close(p[1]);
  if ((fp=fdopen(p[0], "r")) == NULL) Fatal( E_OPEN, cpp, NOSTR );
  return fp;
}

/*************************************************************************/
  FILE *ExecOpen( cmd, redirect )
/*************************************************************************/
char *cmd;
bool redirect;
{
  int p[2];

  /* This is like popen() but we want to redirect the stderr
     as well as the stdout. */

  if (redirect && pipe(p)<0) {
    Err( E_PIPE, NOSTR, NOSTR );
    redirect=false;
  }

  if ((execPid = vfork()) == 0) {
    if (redirect) {
      (void)close(p[0]);
      (void)dup2(p[1],1);
      (void)dup2(p[1],2);
      (void)close(p[1]);
    }
    (void) execl("/bin/sh", "sh", "-c", cmd, (char*)NULL );
    _exit(127);
  }

  if (execPid == FAIL) {
    Err( E_FORK, cmd, NOSTR );
    if (redirect) {
      (void)close(p[0]);
      (void)close(p[1]);
    }
    return NULL;
  }

  if (redirect) {
    (void)close(p[1]);
    return (fdopen(p[0], "r"));
  } else return NULL;
}

/*************************************************************************/
  WAITSTAT ExecClose(fp)
/*************************************************************************/
FILE *fp;
{
  WAITSTAT status;
  int pid;
#ifdef HAVE_SIGPROCMASK
  sigset_t omask,nmask;
#else
  int omask;
#endif

  if (execPid==FAIL) { WAITVAL(status)=0; return status; }
  if (fp!=NULL) (void)fclose(fp);

#ifdef HAVE_SIGPROCMASK
  (void)sigemptyset(&nmask);
  (void)sigaddset(&nmask,SIGINT);
  (void)sigaddset(&nmask,SIGQUIT);
  (void)sigaddset(&nmask,SIGHUP);
  (void)sigprocmask( SIG_BLOCK, &nmask, &omask );
#else
  omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
#endif

  while (((pid=wait(&status))!=execPid) && (pid!=FAIL)) /* wait */ ;

#ifdef HAVE_SIGPROCMASK
  (void)sigprocmask( SIG_SETMASK, &omask, NULL );
#else
  (void)sigsetmask(omask);
#endif

  if (pid==FAIL) WAITVAL(status) = (-1);
  return status;
}

/*************************************************************************/
  static msgtype Category( m )
/*************************************************************************/
msgcode m;
{
  switch(m) {
  case L_CSLINK:
  case L_CFILE:
  case L_CHFILE:
  case L_CNOD:
  case L_CDIR:
  case L_CCDF:
    return M_COPY;

  case L_CDELETE:
  case L_CIGNORE:
  case L_EXISTS:
    return M_NOCOPY;
    
  case L_ERROR:
  case L_PRESERVE:
  case L_IGNORE:
  case L_SAME:
#ifdef LFU_CACHE
  case L_CACHE:
#endif
    return M_NODELETE;

  case L_PARENT:
  case L_DELETE:
  case L_NOSRC:
  case L_TYPES:
  case L_NEWER:
  case L_FORCE:
  case L_NOTLNK:
  case L_LNKVAL:
    return M_DELETE;

  case E_OPEN:
  case E_ACCESS:
  case E_RENAME:
  case E_UNLNK:
  case E_STAT:
  case E_READLNK:
  case E_SLINK:
  case E_HLINK:
  case E_MKDIR:
  case E_READ:
  case E_WRITE:
  case E_TRUNC:
  case E_CLOSE:
  case E_SEEK:
  case E_MKNOD:
  case E_CHOWN:
  case E_CHMOD:
  case E_UTIME:
  case E_WAIT:
  case E_FORK:
  case E_PIPE:
    return (errno==EACCES || errno==EPERM) ? M_PERM : M_SYS;
    
  default:
    return M_OTHER;
  }
}

/*************************************************************************/
  void Message( file, line, msg, arg1, arg2, fp )
/*************************************************************************/
char *file;
int line;
msgcode msg;
char *arg1, *arg2;
FILE *fp;
{

#ifdef LFU_DEBUG
  if (DebugFlag(D_LINE)) (void)fprintf( fp, "[%s:%d] ", BaseName(file), line );
#endif

  switch(Category(msg)) {

  case M_DELETE:
    if (arg2==NULL) (void)fprintf( fp, "Deleted: %s ", arg1 );
    else if (arg2==arg1) (void)fprintf( fp, "Still busy: %s ",arg1, arg2 );
    else (void)fprintf( fp, "Moved: %s to %s ", arg1, arg2 );
    break;
  case M_NODELETE:
    (void)fprintf( fp, "Not deleted: %s ", arg1 );
    break;
  case M_COPY:
    (void)fprintf( fp, "Copied: %s ", arg1 );
    break;
  case M_NOCOPY:
    (void)fprintf( fp, "Not copied: %s ", arg1 );
    break;

  default: break;
  }

  switch (msg) {

  case E_OPEN:
  case E_ACCESS:
  case E_RENAME:
  case E_UNLNK:
  case E_STAT:
  case E_READLNK:
  case E_SLINK:
  case E_HLINK:
  case E_MKDIR:
  case E_READ:
  case E_WRITE:
  case E_TRUNC:
  case E_CLOSE:
  case E_SEEK:
  case E_MKNOD:
  case E_CHMOD:
  case E_UTIME:
  case E_WAIT:
  case E_FORK:
  case E_PIPE:
    (void)fprintf( fp, "%s: %s", sys_errlist[errno], arg1 );
    break;
  case E_CHOWN:
    if (errno==EPERM)
      (void)fprintf( fp, "No permission to change owner: %s", arg1 );
    else (void)fprintf( fp, "%s: %s", sys_errlist[errno], arg1 );
    break;
  case E_MEM:
    (void)fprintf( fp, "Out of memory" );
    break;
  case E_BOOT:
    (void)fprintf( fp, "Can't determine system boot time" );
    break;
  case E_NFS:
    (void)fprintf( fp, "(Perhaps root is being mapped to nobody by NFS)" );
    break;
  case E_NOTHP:
    (void)fprintf( fp, "(Perhaps attempting to handle CDF on non-HP filesystem)" );
    break;
  case E_NOTROOT:
    (void)fprintf( fp, "(Not running as root)" );
    break;
  case E_INTR:
    (void)fprintf( fp, "Interrupted" );
    break;
  case E_INHIBIT:
    (void)fprintf( fp, "Reporting inhibited for following permission errors" );
    break;
  case E_OPTYPE:
    (void)fprintf( fp, "Unknown operator type: %d", (int)arg1 );
    break;
  case E_USER:
    (void)fprintf( fp, "Unknown user: %s", arg1 );
    break;
  case E_GROUP:
    (void)fprintf( fp, "Unknown group: %s", arg1 );
    break;
  case E_REGEXP:
    (void)fprintf( fp, "Error in regexp: %s", arg1 );
    break;
  case E_UNIGRP:
    (void)fprintf( fp, "Netgroup contains user wildcard: %s", arg1 );
    break;
  case E_MTGRP:
    (void)fprintf( fp, "Netgroup/list is empty: %s", arg1 );
    break;
  case E_NOLCHOWN:
    (void)fprintf( fp, "Link ownership not changed: %s", arg1 );
    break;
  case E_NOLCHMOD:
    (void)fprintf( fp, "Link mode not changed: %s", arg1 );
    break;
  case E_MEMBER:
    (void)fprintf( fp, "Netgroup/list contains unknown user: %s (%s)", arg1, arg2 );
    break;
  case E_FSCAN:
    (void)fprintf( fp, "Syntax error in file: %s", arg1 );
    break;
  case E_SSCAN:
    (void)fprintf( fp, "Syntax error in expression: %s", arg1 );
    break;
  case E_FPARSE:
  case E_SPARSE:
    (void)fprintf( fp, "%s (%s)", arg1, arg2 );
    break;
  case E_FSTRING:
    (void)fprintf( fp, "Unterminated string in file: %s", arg1 );
    break;
  case E_SSTRING:
    (void)fprintf( fp, "Unterminated string: %s", arg1 );
    break;
  case E_TOOBUSY:
    (void)fprintf( fp, "Too many copies of busy file: %s", arg1 );
    break;
  case E_CDF:
    (void)fprintf( fp, "Possible problem with CDF: %s%s%s",
		  arg1, arg2 ? "/" : "", arg2 );
    break;
  case E_NOTDIR:
    (void)fprintf( fp, "Not a directory: %s", arg1 );
    break;
  case E_SAME:
    (void)fprintf( fp, "Source and destination are the same: %s = %s",
		       arg1, arg2 );
    break;
  case E_MSGLNK:
    (void)fprintf( fp, "Not all links found: %s", arg1 );
    break;
  case E_NEWER:
    (void)fprintf( fp, "Destination is newer than source: %s", arg1 );
    break;
  case E_DOMAIN:
    (void)fprintf( fp, "%s", arg1 );
    break;
  case E_CWD:
    (void)fprintf( fp, "Can't determine current directory" );
    break;
  case E_SHELL:
    (void)fprintf( fp, "%s: /bin/sh", sys_errlist[errno] );
    break;
  case E_CPP:
    (void)fprintf( fp, "Can't find preprocessor: %s", arg1 );
    break;
  case E_ARGS:
    (void)fprintf( fp, "Too many arguments" );
    break;
  case E_PSYNT:
    (void)fprintf( fp, "Invalid permission specification: %s", arg1 );
    break;
  case E_AGE:
    (void)fprintf( fp, "Invalid age specification: %s", arg1 );
    break;
  case E_SIZE:
    (void)fprintf( fp, "Invalid size specification: %s", arg1 );
    break;
  case E_MISSING:
    (void)fprintf( fp, "Missing %s name: %s", arg1, arg2 );
    break;
  case E_UNSUP:
    (void)fprintf( fp, "Unsupported feature: %s (%s)", arg1, arg2 );
    break;
  case E_TSYNT:
    (void)fprintf( fp, "Invalid file type: %s", arg1 );
    break;
  case E_LONGCMND:
    (void)fprintf( fp, "Command too long: %s", arg1 );
    break;
  case E_DUPUID:
    (void)fprintf( fp, "Multiple UIDs for username: %s", arg1 );
    break;
  case E_FILTYP:
    (void)fprintf( fp, "Unknown file type: %s", arg1 );
    break;
  case E_MON:
    (void)fprintf( fp, "Monitor program error: %s", arg1 );
    break;
  case E_USRERROR:
    (void)fprintf( fp, "%s: %s", arg1, arg2 );
    break;
  case L_CHUID:
    (void)fprintf( fp, "Uid/gid changed: %s", arg1 );
    break;
  case L_CHPERM:
    (void)fprintf( fp, "Perms changed: %s", arg1 );
    break;
  case L_CHTIME:
    (void)fprintf( fp, "Times changed: %s", arg1 );
    break;
  case L_SLINK:
    (void)fprintf( fp, "Linked: %s", arg1 );
    break;
  case L_HLINK:
    (void)fprintf( fp, "Hard-linked: %s", arg1 );
    break;
  case L_EXEC:
    (void)fprintf( fp, "Executing: \"%s\" (%s updated)", arg1, arg2 );
    (void)fflush(fp);
    break;
  case L_EXIT:
    (void)fprintf( fp, "Exited: \"%s\" (status %d)", arg1, (int)arg2 );
    break;
  case L_STOP:
    (void)fprintf( fp, "Stopped: \"%s\" (signal %d)", arg1, (int)arg2 );
    break;
  case L_SIGNAL:
    (void)fprintf( fp, "Interrupted: \"%s\" (signal %d)", arg1, (int)arg2 );
    break;
  case L_OUTPUT:
    (void)fprintf( fp, ">> %s", arg1 );
    (void)fflush(fp);
    break;
  case L_MSKIP:
    (void)fprintf( fp, "Skipping mount point: %s", arg1 );
    (void)fflush(fp);
    break;
  case L_CSLINK:
    (void)fprintf( fp, "(link)", arg1 );
    break;
  case L_CFILE:
    (void)fprintf( fp, "(file)", arg1 );
    break;
  case L_CHFILE:
    (void)fprintf( fp, "(file with holes)", arg1 );
    break;
  case L_CDIR:
    (void)fprintf( fp, "(directory)", arg1 );
    break;
  case L_CCDF:
    (void)fprintf( fp, "(cdf)", arg1 );
    break;
  case L_CNOD:
    (void)fprintf( fp, "(special file)", arg1 );
    break;
  case L_PARENT:
    (void)fprintf( fp, "(parent deleted)" );
    break;
  case L_CDELETE:
  case L_DELETE:
    (void)fprintf( fp, "(delete specified)" );
    break;
  case L_NOSRC:
    (void)fprintf( fp, "(no source file)" );
    break;
  case L_TYPES:
    (void)fprintf( fp, "(source type is different)" );
    break;
  case L_NEWER:
    (void)fprintf( fp, "(source is newer)" );
    break;
  case L_FORCE:
    (void)fprintf( fp, "(force specified)" );
    break;
  case L_NOTLNK:
    (void)fprintf( fp, "(not a link)" );
    break;
  case L_LNKVAL:
    (void)fprintf( fp, "(link has wrong value)" );
    break;
  case L_CIGNORE:
  case L_IGNORE:
    (void)fprintf( fp, "(ignore specified)" );
    break;
  case L_PRESERVE:
    (void)fprintf( fp, "(preserve specified)" );
    break;
  case L_SAME:
    (void)fprintf( fp, "(destination is up to date)" );
    break;
  case L_EXISTS:
    (void)fprintf( fp, "(destination exists)" );
    break;
  case E_OPTION:
    (void)fprintf( fp, "Error in option argument: %s (%s)", arg1, arg2 );
    break;

#ifdef LFU_CACHE
  case E_CPRIO:
    (void)fprintf( fp, "Invalid cache priority: %s", arg1 );
    break;
  case E_FULL:
    (void)fprintf( fp, "File system full: %s", arg1 );
    break;
  case E_CACHE:
    (void)fprintf( fp, "Syntax error in cache file: %s:%s", arg1, arg2 );
    break;
  case L_CCACHE:
    (void)fprintf( fp, "Linked: %s (cache link)", arg1 );
    break;
  case L_NCACHE:
    (void)fprintf( fp, "Not cached: %s", arg1 );
    break;
  case L_UCACHE:
    (void)fprintf( fp, "Decaching: %s (cache=%d)", arg1, (int)arg2 );
    break;
  case L_ECACHE:
    (void)fprintf( fp, "Encaching: %s (cache=%d)", arg1, (int)arg2 );
    break;
  case L_CACHE:
    (void)fprintf( fp, "(destination is a cache link)" );
    break;
#endif /* CACHE */

#ifdef LFU_DEBUG
  case E_DEBUG:
    (void)fprintf( fp, "Bad debug option: %s", arg1 );
    break;
#endif

  default:
    (void)fprintf( fp, "Unknown error (%d)", (int)msg );
    break;
  }
  
  (void)fprintf( fp, "\n" );
}

/*************************************************************************/
  void FatalLine( file, line, msg, arg1, arg2 )
/*************************************************************************/
char *file;
int line;
msgcode msg;
char *arg1, *arg2;
{
  (void)fprintf(stderr, "%s: ", progName );
  Message( file, line, msg, arg1, arg2, stderr );
  exit(1);
}

/*************************************************************************/
  void MsgLine( file, line, msg, arg1, arg2, err )
/*************************************************************************/
char *file;
int line;
msgcode msg;
char *arg1, *arg2;
bool err;
{
  static bool inhibit = false;

  if (err) ++errCount;
  if (Category(msg)==M_PERM) {
    if (inhibit) return;
    fprintf( stdout, "%s: ", err ? "**" : "++" );
    Message( file, line, msg, arg1, arg2, stdout );
    if (optc) MonError( file, line, msg, arg1, arg2 );
    msg= (getuid()) ? E_NOTROOT : E_NFS;

    if (!optr) {
      fprintf( stdout, "%s: ", err ? "**" : "++" );
      Message( file, line, msg, arg1, arg2, stdout );
      if (optc) MonError( file, line, msg, arg1, arg2 );
      inhibit=true;
      msg=E_INHIBIT;
    }
  }

  fprintf( stdout, "%s: ", err ? "**" : "++" );
  Message( file, line, msg, arg1, arg2, stdout );
  if (optc) MonError( file, line, msg, arg1, arg2 );
}

/*************************************************************************/
  void WarnLine( file, line, msg, arg1, arg2 )
/*************************************************************************/
char *file;
int line;
msgcode msg;
char *arg1, *arg2;
{
  if (optw) {
    MsgLine( file, line, msg, arg1, arg2, false );
  }
}

/*************************************************************************/
  void ErrLine( file, line, msg, arg1, arg2 )
/*************************************************************************/
char *file;
int line;
msgcode msg;
char *arg1, *arg2;
{
  MsgLine( file, line, msg, arg1, arg2, true ); 
}

/*************************************************************************/
  void LogLine( file, line, msg, arg1, arg2 )
/*************************************************************************/
char *file;
int line;
msgcode msg;
char *arg1, *arg2;
{
  fprintf( stdout, "  : " );
  Message( file, line, msg, arg1, arg2, stdout );
}

/**************************************************************************
  String functions for systems that don't have them!
**************************************************************************/

#ifndef HAVE_STRCHR
char *strchr(s, c)
char *s, c;
{
  return index(s,c);
}
#endif

#ifndef HAVE_STRPBRK
char *strpbrk(s, set)
char *s, *set;
{
  while (*s) if (index(set, *s)!=NOSTR) return s; else ++s;
  return NOSTR;
}
#endif

#ifndef HAVE_STRSPN
int strspn(s, set)
char *s, *set;
{
  register char *p;
  for (p=s; *p!='\0'; ++p)
    if (index(set, *p)==NOSTR) break;
  return p-s;
}
#endif

#ifndef HAVE_STRCSPN
int strcspn(s, set)
char *s, *set;
{
  register char *p;
  for (p=s; *p!='\0'; ++p)
    if (index(set, *p)!=NOSTR) break;
  return p-s;
}
#endif

#ifndef HAVE_STRTOK
char *strtok(s, seps)
char *s, *seps;
{
  register char	*p, *q;
  static char *oldpos;

  p = (s==NOSTR) ? oldpos: s;
  if (p==NOSTR) return NOSTR;

  q = p + strspn(p, seps);
  if (*q=='\0') return NOSTR;

  if ((p = strpbrk(q, seps)) == NOSTR) oldpos = NOSTR;
  else {
    *p = '\0';
    oldpos = ++p;
  }
  return q;
}
#endif

/**************************************************************************
  Systems that don't have alloca can use the GNU one
**************************************************************************/

void *xmalloc(s) int s; { return (void*)NewMem(s); }

#ifndef HAVE_ALLOCA
#include "alloca.c"
#endif
lfu-3.1.5/src/parse.y   644  75362  74430       43253  6514416275   7642 %{
/**************************************************************************

  The Program parser.

  $Author: paul $
  $Revision: 1.3 $
  $Date: 1998/03/31 15:39:07 $

  Copyright (c) 1992 by the University of Edinburgh
  Laboratory for the Foundations of Computer Science
  Department of Computer Science
  Written by Paul Anderson.

  Permission is granted to anyone to use this software for any
  purpose on any computer system, and to redistribute it freely,
  subject to the following restrictions:

  The University of Edinburgh makes no representations about the
  suitability of this software for any purpose.  It is
  provided "as is" without express or implied warranty.

  The origin of this software must not be misrepresented, either by
  explicit claim or by omission, and this copyright notice must appear in
  all copies of the software. Altered versions must be plainly marked
  as such, and must not be misrepresented as being the original software.

  The name of the University of Edinburgh must not be used in
  advertising or publicity pertaining to distribution of the software
  without specific, written prior permission. 
 
**************************************************************************/

#define _PARSE_C

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include "misc.h"
#include <string.h>
#include "eval.h"
#include "scan.h"
#include "avl.h"
#ifdef LFU_CACHE
#include "cache.h"
#endif
#include "parse.h"

#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#else
extern char *alloca();
#endif

extern int yyerror();
extern int yylex();

/**************************************************************************
  Verbose error reporting
**************************************************************************/

#ifdef YYDEBUG
#undef HAVE_VERBOSE_PARSER_MSGS
#endif

#ifdef HAVE_VERBOSE_PARSER_MSGS

#define yyerror(msg) VerboseErr(yystate,msg)
#define xmalloc(n) malloc(n)

#ifdef PARSE_DEBUG
#define TokenClass(a,b) b
#else
#define TokenClass(a,b) a
#endif

/* Beware - the order of these strings must be the same as the order in
   which the tokens are declared */

static char *yytname[] = {
  TokenClass(NOSTR,"T_$"),
  TokenClass(NOSTR,"T_error"),
  TokenClass(NOSTR,"T_$illegal"),
  TokenClass("default","T_DEFAULT"),
  TokenClass("string","T_STRING"),
  TokenClass("block","T_LBR"),
  TokenClass("'}'","T_RBR"),
  TokenClass("condition","T_LPAR"),
  TokenClass("')'","T_RPAR"),
  TokenClass("[","T_LSQ"),
  TokenClass("']'","T_RSQ"),
  TokenClass("'='","T_EQ"),
  TokenClass("'!='","T_NEQ"),
  TokenClass("operator","T_AND"),
  TokenClass("operator","T_OR"),
  TokenClass("condition","T_NOT"),
  TokenClass("action","T_TILDE"),
  TokenClass("';'","T_SEMI"),
  TokenClass("'else'","T_ELSE"),
  TokenClass("'>'","T_GT"),
  TokenClass("'<'","T_LT"),
  TokenClass("condition","T_NAME"),
  TokenClass("condition","T_OWNER"),
  TokenClass("condition","T_GROUP"),
  TokenClass("condition","T_TYPE"),
  TokenClass("condition","T_PATH"),
  TokenClass("condition","T_AGE"),
  TokenClass("condition","T_MODE"),
  TokenClass("condition","T_ACCESS"),
  TokenClass("condition","T_SIZE"),
  TokenClass("condition","T_EXISTS"),
  TokenClass("condition","T_REBOOT"),
  TokenClass("action","T_ERROR"),
  TokenClass("action","T_CHGRP"),
  TokenClass("action","T_CHOWN"),
  TokenClass("action","T_LOGALL"),
  TokenClass("action","T_INHERIT"),
  TokenClass("action","T_CDF"),
  TokenClass("action","T_STATS"),
  TokenClass("action","T_UPDATE"),
  TokenClass("action","T_PRESERVE"),
  TokenClass("action","T_DELETE"),
  TokenClass("action","T_IGNORE"),
  TokenClass("action","T_SOURCE"),
  TokenClass("action","T_WARN"),
  TokenClass("action","T_LNK"),
  TokenClass("action","T_KEEP"),
  TokenClass("action","T_LOG"),
  TokenClass("action","T_FORCE"),
  TokenClass("action","T_FILL"),
  TokenClass("action","T_CHMOD"),
  TokenClass("action","T_NEWER"),
  TokenClass("action","T_EXEC"),
  TokenClass("action","T_NEWTIME"),
  TokenClass("action","T_SHADOW"),
  TokenClass("action","T_FOLLOW"),
  TokenClass("action","T_COMPRESS"),
  TokenClass("action","T_AUTO"),
  TokenClass("option","T_NOMOUNT"),
  TokenClass("action","T_CACHE"),
  TokenClass("option","T_CACHEFILE"),
  TokenClass("option","T_CACHEMINSIZE"),
  TokenClass("option","T_CACHEMINFREE"),
  TokenClass("option","T_CACHEMINVALUE"),
  TokenClass("option","T_CACHEFILL"),
  TokenClass("option","T_NOIDCHECK"),
};

#endif

%}

/**************************************************************************
  Tokens
**************************************************************************/

%union {
  char *string;
  struct _PROG *prog;
  int none;
}

/* Section headers */
%token <none>   T_DEFAULT

/* Strings */
%token <string> T_STRING

/* Operators */
%token <none>   T_LBR T_RBR T_LPAR T_RPAR T_LSQ T_RSQ T_EQ T_NEQ
%token <none>   T_AND T_OR T_NOT T_TILDE T_SEMI T_ELSE T_GT T_LT

/* Conditions*/
%token <none>   T_NAME T_OWNER T_GROUP T_TYPE T_PATH T_AGE T_MODE
%token <none>   T_ACCESS, T_SIZE T_EXISTS T_REBOOT

/* Actions */
%token <none>   T_ERROR T_CHGRP T_CHOWN T_LOGALL T_INHERIT T_CDF T_STATS
%token <none>   T_UPDATE T_PRESERVE T_DELETE T_IGNORE T_SOURCE T_WARN
%token <none>   T_LNK T_KEEP T_LOG T_FORCE T_FILL T_CHMOD T_NEWER
%token <none>   T_EXEC T_NEWTIME T_SHADOW T_FOLLOW T_COMPRESS T_AUTO
%token <none>   T_NOMOUNT
%token <none>   T_CACHE T_CACHEFILE T_CACHEMINSIZE T_CACHEMINVALUE T_CACHEFILL
%token <none>   T_CACHEMINFREE T_NOIDCHECK

%type  <prog>   program statement condition primary action term block section
%type  <prog>   deflist default defblock
%type  <string> string stringlist arg
%type  <none>   option

%left           T_OR
%left           T_AND

/**************************************************************************
  The Parser
**************************************************************************/

/* We expect one conflict because of the "dangling else" ambiguity */

%expect 1
%start program

%%

program         : 
                  { $$=theProg=NOPROG; }
                | section
                  { $$=theProg=$1; }

section         : defblock
                  { $$=$1; }
		| statement
                  { $$=$1; }
                | section defblock
                  { $$=$1; }
		| section statement
                  { $$ = ($1==NOPROG) ? $2 : New2Op( I_SEQ, $1, $2 ); }

defblock        : T_DEFAULT T_LBR deflist T_RBR
                  { if ($3!=NOPROG) EvalDefault($3); $$=NOPROG; }

deflist         : default
                  { $$=$1; }
                | default deflist
                  { $$ = ($1==NOPROG) ? $2 : New2Op( I_SEQ, $1, $2 ); }

default         : option T_SEMI
                  { $$=NOPROG; }
                | action T_SEMI
                  { $$=$1; }

block		: statement
                  { $$=$1; }
		| block statement
                  { $$=New2Op( I_SEQ, $1, $2 ); }

statement	: action T_SEMI
                  { $$=$1; }
                | T_LBR block T_RBR
                  { $$=$2; }
		| condition statement
                  { $$=New3Op( I_COND, $1, $2, NOPROG 
Results 1 - 1
Help - FTP Sites List - Software Dir.
Searching half a billion files worldwide
© 1997-2009 MARUHN Internet Solutions