1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Rebooting 93u+m

This commit reboots ksh 93u+m development with a new fork based off
the archived official AT&T ast repo, master branch.

README:
- Removed. Having two READMEs is a botch.

README.md:
- Imported and edited from the archived fork,
  https://github.com/modernish/ksh -- the newer instructions will
  become applicable as I cherry-pick all the changes from there :)
    - Copy-edits.
    - Added policy and rationale for this 93u+m fork.
    - Incorporated info from old README that is still relevant.

.gitignore:
- Added.

bin/execrate:
- Removed. This one keeps changing its license header, causing git
  to show an uncommitted file. It's always re-copied anyway, and
  not for direct invocation, so, exclude and add to .gitignore.
  The source file is: src/cmd/INIT/execrate.sh

src/cmd/*,
src/lib/*:
- Remove historical baggage: everything except ksh93 and
  dependencies. This is the same stuff the ksh-community fork
  removed. I wouldn't mind keeping it, but some of this stuff
  causes build failures on macOS (and probably other systems), and
  I need to get on with fixing ksh93.
     Hopefully, we can figure out how to re-add stuff we can use
  later -- particularly the pty command (pseudo-terminal utility
  for scripting interactive sessions) which is needed for
  regression-testing the interactive shell.
This commit is contained in:
Martijn Dekker 2020-06-12 01:43:13 +02:00
parent cc1f2bf81d
commit 2940b3f536
2271 changed files with 93 additions and 1162987 deletions

View file

@ -1,15 +0,0 @@
:PACKAGE: ast
LICENSE = since=2002,author=gsf+dgk
ardir :LIBRARY: ardir.c \
ar-aix.c ar-aixbig.c ar-local.c ar-omf.c \
ar-pdp11.c ar-port.c ar-s5r0.c
$(INCLUDEDIR) :INSTALLPROTO: ardir.h
:INSTALLDIR: testar
testar :: testar.c -lardir
:: RELEASE

View file

@ -1,302 +0,0 @@
info mam static 00000 1994-07-17 make (AT&T Research) 5.7 2012-06-20
setv INSTALLROOT ../../..
setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast
setv PACKAGE_ast_LIB ${INSTALLROOT}/lib
setv PACKAGEROOT ../../../../..
setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS}
setv ARFLAGS rc
setv AS as
setv ASFLAGS
setv CC cc
setv mam_cc_FLAGS
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
setv COTEMP $$
setv CPIO cpio
setv CPIOFLAGS
setv CPP "${CC} -E"
setv F77 f77
setv HOSTCC ${CC}
setv IGNORE
setv LD ld
setv LDFLAGS
setv LEX lex
setv LEXFLAGS
setv LPR lpr
setv LPRFLAGS
setv M4FLAGS
setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
setv SHELL /bin/sh
setv SILENT
setv TAR tar
setv YACC yacc
setv YACCFLAGS -d
make ${PACKAGEROOT}/lib/package/ast.lic
done ${PACKAGEROOT}/lib/package/ast.lic
make install
make ardir
make libardir.a archive
make ardir.req
exec - set -
exec - echo 'int main(){return 0;}' > 1.${COTEMP}.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -c 1.${COTEMP}.c &&
exec - x=`${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l'*' 2>&1 | sed -e 's/[][()+@?]/#/g' || :` &&
exec - {
exec - case "" in
exec - *?) echo " " ;;
exec - esac
exec - for i in ardir ast
exec - do case $i in
exec - "ardir"|ardir)
exec - ;;
exec - *) if test -f ${INSTALLROOT}/lib/lib/$i
exec - then y=`cat ${INSTALLROOT}/lib/lib/$i`
exec - case $y in
exec - *-?*) echo "" $y ;;
exec - esac
exec - continue
exec - elif test ! -f ${INSTALLROOT}/lib/lib$i.a
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) continue ;;
exec - esac
exec - ;;
exec - esac
exec - fi
exec - ;;
exec - esac
exec - echo " -l$i"
exec - done
exec - } > ardir.req
exec - rm -f 1.${COTEMP}.*
done ardir.req generated
make ardir.o
make ardir.c
make ardirlib.h implicit
make ${PACKAGE_ast_INCLUDE}/error.h implicit
make ${PACKAGE_ast_INCLUDE}/option.h implicit
make ${PACKAGE_ast_INCLUDE}/ast.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_api.h dontcare
make ${PACKAGE_ast_INCLUDE}/vmalloc.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_map.h dontcare
make ${PACKAGE_ast_INCLUDE}/endian.h implicit
make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
done ${PACKAGE_ast_INCLUDE}/bytesex.h dontcare
done ${PACKAGE_ast_INCLUDE}/endian.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_common.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
make ${PACKAGE_ast_INCLUDE}/regex.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
make ${PACKAGE_ast_INCLUDE}/wctype.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
make ${PACKAGE_ast_INCLUDE}/wchar.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
done ${PACKAGE_ast_INCLUDE}/wchar.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_wctype.h dontcare
done ${PACKAGE_ast_INCLUDE}/wctype.h dontcare
make ${PACKAGE_ast_INCLUDE}/stdio.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit
make ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio_s.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_stdio.h dontcare
done ${PACKAGE_ast_INCLUDE}/stdio.h dontcare
prev ${PACKAGE_ast_INCLUDE}/stdio.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_wchar.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
make ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/prototyped.h dontcare
done ${PACKAGE_ast_INCLUDE}/regex.h dontcare
make ${PACKAGE_ast_INCLUDE}/getopt.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_getopt.h dontcare
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/getopt.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_botch.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_botch.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_limits.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_limits.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_fcntl.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_fs.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_fs.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_fcntl.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_sys.h implicit
prev ${PACKAGE_ast_INCLUDE}/getopt.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_sys.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_lib.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_lib.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_std.h dontcare
done ${PACKAGE_ast_INCLUDE}/vmalloc.h dontcare
make ${PACKAGE_ast_INCLUDE}/sfio.h implicit
prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast.h dontcare
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/option.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/error.h dontcare
make ardir.h implicit
make ${PACKAGE_ast_INCLUDE}/ls.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_mode.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_mode.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_fs.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ls.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
done ardir.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
done ardirlib.h
done ardir.c
meta ardir.o %.c>%.o ardir.c ardir
prev ardir.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -c ardir.c
done ardir.o generated
make ar-aix.o
make ar-aix.c
make ${PACKAGE_ast_INCLUDE}/tm.h implicit
make ${PACKAGE_ast_INCLUDE}/times.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_time.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_time.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/times.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/tm.h
prev ardirlib.h implicit
done ar-aix.c
meta ar-aix.o %.c>%.o ar-aix.c ar-aix
prev ar-aix.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -c ar-aix.c
done ar-aix.o generated
make ar-aixbig.o
make ar-aixbig.c
prev ${PACKAGE_ast_INCLUDE}/tm.h implicit
prev ardirlib.h implicit
done ar-aixbig.c
meta ar-aixbig.o %.c>%.o ar-aixbig.c ar-aixbig
prev ar-aixbig.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -c ar-aixbig.c
done ar-aixbig.o generated
make ar-local.o
make ar-local.c
prev ${PACKAGE_ast_INCLUDE}/tm.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev ardirlib.h implicit
done ar-local.c
meta ar-local.o %.c>%.o ar-local.c ar-local
prev ar-local.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -c ar-local.c
done ar-local.o generated
make ar-omf.o
make ar-omf.c
make omf.h implicit
done omf.h
make ${PACKAGE_ast_INCLUDE}/cdt.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/cdt.h
prev ardirlib.h implicit
done ar-omf.c
meta ar-omf.o %.c>%.o ar-omf.c ar-omf
prev ar-omf.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -c ar-omf.c
done ar-omf.o generated
make ar-pdp11.o
make ar-pdp11.c
prev ${PACKAGE_ast_INCLUDE}/tm.h implicit
make ${PACKAGE_ast_INCLUDE}/swap.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/swap.h
prev ardirlib.h implicit
done ar-pdp11.c
meta ar-pdp11.o %.c>%.o ar-pdp11.c ar-pdp11
prev ar-pdp11.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -c ar-pdp11.c
done ar-pdp11.o generated
make ar-port.o
make ar-port.c
prev ${PACKAGE_ast_INCLUDE}/tm.h implicit
prev ardirlib.h implicit
done ar-port.c
meta ar-port.o %.c>%.o ar-port.c ar-port
prev ar-port.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -c ar-port.c
done ar-port.o generated
make ar-s5r0.o
make ar-s5r0.c
prev ${PACKAGE_ast_INCLUDE}/tm.h implicit
prev ${PACKAGE_ast_INCLUDE}/swap.h implicit
prev ardirlib.h implicit
done ar-s5r0.c
meta ar-s5r0.o %.c>%.o ar-s5r0.c ar-s5r0
prev ar-s5r0.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -c ar-s5r0.c
done ar-s5r0.o generated
exec - ${AR} rc libardir.a ardir.o ar-aix.o ar-aixbig.o ar-local.o ar-omf.o ar-pdp11.o ar-port.o ar-s5r0.o
exec - (ranlib libardir.a) >/dev/null 2>&1 || true
done libardir.a generated
done ardir virtual
prev libardir.a archive
make ${INSTALLROOT}/lib
exec - if silent test ! -d ${INSTALLROOT}/lib
exec - then mkdir -p ${INSTALLROOT}/lib
exec - fi
done ${INSTALLROOT}/lib generated
make ${INSTALLROOT}/lib/libardir.a archive
prev ${INSTALLROOT}/lib
prev libardir.a archive
exec - test '' = 'libardir.a' || ${STDCMP} 2>/dev/null -s libardir.a ${INSTALLROOT}/lib/libardir.a || { ${STDMV} ${INSTALLROOT}/lib/libardir.a ${INSTALLROOT}/lib/libardir.a.old 2>/dev/null || true; ${STDCP} libardir.a ${INSTALLROOT}/lib/libardir.a ;}
exec - (ranlib ${INSTALLROOT}/lib/libardir.a) >/dev/null 2>&1 || true
done ${INSTALLROOT}/lib/libardir.a generated
make ${INSTALLROOT}/lib/lib
exec - if silent test ! -d ${INSTALLROOT}/lib/lib
exec - then mkdir -p ${INSTALLROOT}/lib/lib
exec - fi
done ${INSTALLROOT}/lib/lib generated
make ${INSTALLROOT}/lib/lib/ardir
prev ${INSTALLROOT}/lib/lib
prev ardir.req
exec - test '' = 'ardir.req' || ${STDCMP} 2>/dev/null -s ardir.req ${INSTALLROOT}/lib/lib/ardir || { ${STDMV} ${INSTALLROOT}/lib/lib/ardir ${INSTALLROOT}/lib/lib/ardir.old 2>/dev/null || true; ${STDCP} ardir.req ${INSTALLROOT}/lib/lib/ardir ;}
done ${INSTALLROOT}/lib/lib/ardir generated
make ${PACKAGE_ast_INCLUDE}
exec - if silent test ! -d ${PACKAGE_ast_INCLUDE}
exec - then mkdir -p ${PACKAGE_ast_INCLUDE}
exec - fi
done ${PACKAGE_ast_INCLUDE} generated
make ${PACKAGE_ast_INCLUDE}/ardir.h
prev ${PACKAGE_ast_INCLUDE}
prev ardir.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=2002,author=gsf+dgk' ardir.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/ardir.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/ardir.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/ardir.h generated
done install virtual
make test
done test dontcare virtual

View file

@ -1,11 +0,0 @@
111-08-31 ar-omf.c: fix FILENAME #pragma prototyped incompatibility
03-09-17 ardir.c: rewind initial peek to open position in case its /dev/stdin
03-04-05 ar-port.c: fix bug that skipped initial long name entry
ar-port.c: handle netbsd.i386 ' <long-index>' vs. '/<long-index>'
03-02-05 ar-port.c: handle solaris TYPE_port variation
03-01-30 ar-port.c: handle member name length == 16 (no terminator)
02-10-20 ardir.c: add ardirlist()
02-08-09 ardir.c: ardiropen() fails if !S_ISREG unless ARDIR_FORCE
02-06-11 ar-port.c: handle 4.4BSD `#1/size' long names
02-06-06 #ifndef EILSEQ => EINVAL
02-05-07 first release

View file

@ -1,255 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* aix archive format method
*/
#include <ardirlib.h>
#include <tm.h>
#define MAGIC "<aiaff>\n"
#define MAGIC_SIZE 8
typedef struct Header_s
{
char fl_magic[MAGIC_SIZE];
char fl_memoff[12];
char fl_gstoff[12];
char fl_fstmoff[12];
char fl_lstmoff[12];
char fl_freeoff[12];
} Header_t;
typedef struct Member_s
{
char ar_size[12];
char ar_nxtmem[12];
char ar_prvmem[12];
char ar_date[12];
char ar_uid[12];
char ar_gid[12];
char ar_mode[12];
char ar_namlen[4];
union
{
char ar_name[2];
char ar_fmag[2];
} _ar_name;
} Member_t;
typedef struct State_s /* method state */
{
off_t current; /* current dirent offset */
off_t offset; /* next dirent offset */
off_t last; /* last member offset */
Member_t member; /* current member */
int term; /* trailing '\0' for member */
char* name; /* current member name */
size_t namesize; /* max size for name */
} State_t;
/*
* closef
*/
static int
aixclose(Ardir_t* ar)
{
State_t* state;
if (ar && (state = (State_t*)ar->data))
{
if (state->name)
free(state->name);
free(state);
}
return 0;
}
/*
* openf
*/
static int
aixopen(Ardir_t* ar, char* buf, size_t n)
{
Header_t* hdr;
State_t* state;
long m;
if (n <= sizeof(Header_t))
return -1;
hdr = (Header_t*)buf;
if (memcmp(hdr->fl_magic, MAGIC, MAGIC_SIZE))
return -1;
if (!(state = newof(0, State_t, 1, 0)))
return -1;
ar->data = (void*)state;
if (sfsscanf(hdr->fl_gstoff, "%ld", &m) != 1)
goto nope;
if (sfsscanf(hdr->fl_fstmoff, "%ld", &m) != 1)
goto nope;
state->offset = m;
if (sfsscanf(hdr->fl_memoff, "%ld", &m) != 1)
goto nope;
state->last = m;
return 0;
nope:
aixclose(ar);
return -1;
}
/*
* nextf
*/
static Ardirent_t*
aixnext(Ardir_t* ar)
{
State_t* state = (State_t*)ar->data;
long n;
unsigned long u;
if ((state->current = state->offset) >= state->last)
return 0;
if (lseek(ar->fd, state->offset, SEEK_SET) != state->offset)
{
ar->error = errno;
return 0;
}
if (read(ar->fd, (char*)&state->member, sizeof(state->member)) != sizeof(state->member))
{
if ((n = read(ar->fd, (char*)&state->member, 1)) < 0)
ar->error = errno;
else if (n > 0)
ar->error = EINVAL;
return 0;
}
if (sfsscanf(state->member.ar_namlen, "%ld", &n) != 1)
{
ar->error = EINVAL;
return 0;
}
if (n >= state->namesize)
{
state->namesize = roundof(n + 1, 256);
if (!(state->name = newof(state->name, char, state->namesize, 0)))
{
ar->error = errno;
return 0;
}
ar->dirent.name = state->name;
}
strncpy(state->name, state->member._ar_name.ar_name, 2);
if (n > 2)
{
if (read(ar->fd, state->name + 2, n - 2) != (n - 2))
{
ar->error = errno;
return 0;
}
if (lseek(ar->fd, -(Sfoff_t)(n - 2), SEEK_CUR) < 0)
{
ar->error = errno;
return 0;
}
}
state->name[n] = 0;
ar->dirent.offset = state->offset + sizeof(Member_t) + n - 2;
if (sfsscanf(state->member.ar_date, "%lu", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.mtime = u;
if (sfsscanf(state->member.ar_uid, "%lu", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.uid = u;
if (sfsscanf(state->member.ar_gid, "%lu", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.gid = u;
if (sfsscanf(state->member.ar_mode, "%lo", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.mode = u;
if (sfsscanf(state->member.ar_size, "%ld", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.size = u;
if (sfsscanf(state->member.ar_nxtmem, "%ld", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
state->offset = u;
return &ar->dirent;
}
/*
* changef
*/
static int
aixchange(Ardir_t* ar, Ardirent_t* ent)
{
State_t* state = (State_t*)ar->data;
off_t o;
char buf[sizeof(state->member.ar_date) + 1];
o = state->current + offsetof(Member_t, ar_date);
if (lseek(ar->fd, o, SEEK_SET) != o)
{
ar->error = errno;
return -1;
}
sfsprintf(buf, sizeof(buf), "%-*lu", sizeof(buf) - 1, (unsigned long)ent->mtime);
if (write(ar->fd, buf, sizeof(buf) - 1) != (sizeof(buf) - 1))
{
ar->error = errno;
return -1;
}
return 0;
}
Ardirmeth_t ar_aix =
{
"aix",
"aix archive",
aixopen,
aixnext,
aixchange,
0,
0,
aixclose,
ar_aix_next
};

View file

@ -1,256 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* aixbig archive format method
*/
#include <ardirlib.h>
#include <tm.h>
#define MAGIC "<bigaf>\n"
#define MAGIC_SIZE 8
typedef struct Header_s
{
char fl_magic[MAGIC_SIZE];
char fl_memoff[20];
char fl_gstoff[20];
char fl_gst64off[20];
char fl_fstmoff[20];
char fl_lstmoff[20];
char fl_freeoff[20];
} Header_t;
typedef struct Member_s
{
char ar_size[20];
char ar_nxtmem[20];
char ar_prvmem[20];
char ar_date[12];
char ar_uid[12];
char ar_gid[12];
char ar_mode[12];
char ar_namlen[4];
union
{
char ar_name[2];
char ar_fmag[2];
} _ar_name;
} Member_t;
typedef struct State_s /* method state */
{
off_t current; /* current dirent offset */
off_t offset; /* next dirent offset */
off_t last; /* last member offset */
Member_t member; /* current member */
int term; /* trailing '\0' for member */
char* name; /* current member name */
size_t namesize; /* max size for name */
} State_t;
/*
* closef
*/
static int
aixbigclose(Ardir_t* ar)
{
State_t* state;
if (ar && (state = (State_t*)ar->data))
{
if (state->name)
free(state->name);
free(state);
}
return 0;
}
/*
* openf
*/
static int
aixbigopen(Ardir_t* ar, char* buf, size_t n)
{
Header_t* hdr;
State_t* state;
long m;
if (n <= sizeof(Header_t))
return -1;
hdr = (Header_t*)buf;
if (memcmp(hdr->fl_magic, MAGIC, MAGIC_SIZE))
return -1;
if (!(state = newof(0, State_t, 1, 0)))
return -1;
ar->data = (void*)state;
if (sfsscanf(hdr->fl_gstoff, "%ld", &m) != 1)
goto nope;
if (sfsscanf(hdr->fl_fstmoff, "%ld", &m) != 1)
goto nope;
state->offset = m;
if (sfsscanf(hdr->fl_memoff, "%ld", &m) != 1)
goto nope;
state->last = m;
return 0;
nope:
aixbigclose(ar);
return -1;
}
/*
* nextf
*/
static Ardirent_t*
aixbignext(Ardir_t* ar)
{
State_t* state = (State_t*)ar->data;
long n;
unsigned long u;
if ((state->current = state->offset) >= state->last)
return 0;
if (lseek(ar->fd, state->offset, SEEK_SET) != state->offset)
{
ar->error = errno;
return 0;
}
if (read(ar->fd, (char*)&state->member, sizeof(state->member)) != sizeof(state->member))
{
if ((n = read(ar->fd, (char*)&state->member, 1)) < 0)
ar->error = errno;
else if (n > 0)
ar->error = EINVAL;
return 0;
}
if (sfsscanf(state->member.ar_namlen, "%ld", &n) != 1)
{
ar->error = EINVAL;
return 0;
}
if (n >= state->namesize)
{
state->namesize = roundof(n + 1, 256);
if (!(state->name = newof(state->name, char, state->namesize, 0)))
{
ar->error = errno;
return 0;
}
ar->dirent.name = state->name;
}
memcpy(state->name, state->member._ar_name.ar_name, 2);
if (n > 2)
{
if (read(ar->fd, state->name + 2, n - 2) != (n - 2))
{
ar->error = errno;
return 0;
}
if (lseek(ar->fd, -(Sfoff_t)(n - 2), SEEK_CUR) < 0)
{
ar->error = errno;
return 0;
}
}
state->name[n] = 0;
ar->dirent.offset = state->offset + sizeof(Member_t) + n - 2;
if (sfsscanf(state->member.ar_date, "%lu", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.mtime = u;
if (sfsscanf(state->member.ar_uid, "%lu", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.uid = u;
if (sfsscanf(state->member.ar_gid, "%lu", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.gid = u;
if (sfsscanf(state->member.ar_mode, "%lo", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.mode = u;
if (sfsscanf(state->member.ar_size, "%ld", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.size = u;
if (sfsscanf(state->member.ar_nxtmem, "%ld", &u) != 1)
{
ar->error = EINVAL;
return 0;
}
state->offset = u;
return &ar->dirent;
}
/*
* changef
*/
static int
aixbigchange(Ardir_t* ar, Ardirent_t* ent)
{
State_t* state = (State_t*)ar->data;
off_t o;
char buf[sizeof(state->member.ar_date) + 1];
o = state->current + offsetof(Member_t, ar_date);
if (lseek(ar->fd, o, SEEK_SET) != o)
{
ar->error = errno;
return -1;
}
sfsprintf(buf, sizeof(buf), "%-*lu", sizeof(buf) - 1, (unsigned long)ent->mtime);
if (write(ar->fd, buf, sizeof(buf) - 1) != (sizeof(buf) - 1))
{
ar->error = errno;
return -1;
}
return 0;
}
Ardirmeth_t ar_aixbig =
{
"aixbig",
"aixbig archive",
aixbigopen,
aixbignext,
aixbigchange,
0,
0,
aixbigclose,
ar_aixbig_next
};

View file

@ -1,147 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* local archive format method
*/
#include <ardirlib.h>
#include <ctype.h>
#include <tm.h>
#define SYMDIR_local "(._|_.|__.|___|*/)*"
typedef struct State_s /* method state */
{
Sfio_t* sp; /* sfpopen() stream */
unsigned long count; /* member count */
} State_t;
/*
* closef
*/
static int
localclose(Ardir_t* ar)
{
State_t* state;
int r;
if (!ar || !(state = (State_t*)ar->data))
r = -1;
else
{
if (!state->sp || sfclose(state->sp))
r = -1;
else
r = 0;
free(state);
}
return r;
}
/*
* openf
*/
static int
localopen(Ardir_t* ar, char* buf, size_t n)
{
State_t* state;
char* cmd;
int c;
if (!(ar->flags & ARDIR_LOCAL))
return -1;
if (!(state = newof(0, State_t, 1, 0)))
return -1;
ar->data = (void*)state;
cmd = sfprints("${ARDIR:-ar} ${ARDIRFLAGS:-tv} '%s' 2>/dev/null", ar->path);
if (!(state->sp = sfpopen(NiL, cmd, "r")) || (c = sfgetc(state->sp)) == EOF || sfungetc(state->sp, c) == EOF)
{
localclose(ar);
return -1;
}
return 0;
}
/*
* nextf
*/
static Ardirent_t*
localnext(Ardir_t* ar)
{
State_t* state = (State_t*)ar->data;
register char* s;
register char* t;
char* e;
int n;
while (s = sfgetr(state->sp, '\n', 1))
{
/*
* assume ``junk Mmm ... member''
*/
if (!(t = strrchr(s, ' ')))
continue;
*t++ = 0;
if (state->count++ || !strmatch(t, SYMDIR_local))
while (s = strchr(s, ' '))
{
if (isupper(*++s) && islower(s[1]) && islower(s[2]) && s[3] == ' ')
{
ar->dirent.mtime = tmdate(s, &e, NiL);
if (!*e)
{
if ((n = strlen(t)) > ar->truncate)
ar->truncate = n;
break;
}
}
else
ar->dirent.size = strtoul(s, NiL, 10);
}
ar->dirent.name = t;
ar->dirent.uid = ar->st.st_uid;
ar->dirent.gid = ar->st.st_gid;
ar->dirent.mode = ar->st.st_mode;
ar->dirent.offset = -1;
return &ar->dirent;
}
if (sferror(state->sp))
ar->error = errno;
return 0;
}
Ardirmeth_t ar_local =
{
"local",
"local ar archive",
localopen,
localnext,
0,
0,
0,
localclose,
ar_local_next
};

View file

@ -1,486 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* omf archive format method
*/
#include <ardirlib.h>
#include <cdt.h>
#include <omf.h>
#ifndef EILSEQ
#define EILSEQ EINVAL
#endif
#define FILENAME "U_w_i_n.o"
typedef struct _arfile_
{
Ardirent_t st;
char *alias;
Dtlink_t link;
int flags;
size_t toffset;
char suffix[4];
} Arfile_t;
typedef struct State_s /* method state */
{
Dt_t *dict;
void *addr;
Arfile_t lib;
Arfile_t *next;
int state;
} State_t;
struct Table
{
struct Table *next;
size_t offset;
size_t disp;
};
static int namcomp(Dt_t *dp, Void_t *left, Void_t *right, Dtdisc_t *dsp)
{
char *l= (char*)left;
char *r= (char*)right;
char *suffix;
if(suffix=strrchr(l,'.'))
return(memcmp(l,r,suffix+1-l));
return(strcmp(l,r));
}
static int offcomp(Dt_t *dp, Void_t *left, Void_t *right, Dtdisc_t *dsp)
{
off_t l= *((off_t*)left);
off_t r= *((off_t*)right);
if (l < r)
return -1;
if (l > r)
return 1;
return 0;
}
static Dtdisc_t namdisc =
{
offsetof(Arfile_t,st.name),-1, offsetof(Arfile_t,link), 0, 0, namcomp
};
static Dtdisc_t offdisc =
{
offsetof(Arfile_t,st.offset), sizeof(off_t), offsetof(Arfile_t,link), 0, 0, offcomp
};
static unsigned char *readint(unsigned char *cp,int *i, int big)
{
if(big)
{
*i = (*cp) | (cp[1]<<8) | (cp[2]<<16) | (cp[3]<<24);
return(cp+4);
}
*i = (*cp) | (cp[1]<<8);
return(cp+2);
}
static unsigned char *readindex(unsigned char *cp, int *size)
{
if(*cp&0x80)
{
*size = (*cp&0xf7)<<8 | cp[1];
return(cp+2);
}
*size = *cp++;
return(cp);
}
#define round(a,b) (((a)+(b)-1) &~ ((b)-1))
static unsigned int is_omf(int fd)
{
unsigned char buff[4];
if(read(fd,buff,4) != 4)
return(0);
if(*buff==OMF_THEADR)
return(buff[3]);
lseek(fd,(off_t)-4,SEEK_CUR);
errno = EILSEQ;
return(0);
}
static Arfile_t *ar_getnode(Ardir_t *ar, const char *name)
{
const char *cp;
Arfile_t *fp;
Dt_t *dp = ((State_t*)ar->data)->dict;
if(cp = strrchr(name,'/'))
name = cp+1;
fp = (Arfile_t*)dtmatch(dp,(void*)name);
if(!fp)
{
size_t len = strlen(name)+5;
if(!(fp = newof(0,Arfile_t,1,len)))
return(0);
fp->st.name = (char*)(fp+1);
memcpy((char*)fp->st.name,name,len);
if(!strrchr(fp->st.name,'.'))
{
fp->st.name[len-5] = '.';
fp->st.name[len-4] = 0;
}
fp->suffix[0] = 'o';
fp->suffix[1] = 0;
fp->st.mtime = ar->st.st_mtime;
fp->st.mode = ar->st.st_mode&(S_IRWXU|S_IRWXG|S_IRWXO);
fp->st.uid = ar->st.st_uid;
fp->st.gid = ar->st.st_gid;
dtinsert(dp,fp);
}
return(fp);
}
/*
* closef
*/
static int
omfclose(Ardir_t* ar)
{
State_t *sp = (State_t*)ar->data;
Dt_t *dp = sp?sp->dict:0;
if(sp && dp && sp->state)
{
/* update modification times */
Arfile_t *fp;
for(fp=(Arfile_t*)dtfirst(dp); fp; fp = (Arfile_t*)dtnext(dp,fp))
{
if(fp->flags && fp->toffset>0 && lseek(ar->fd,(off_t)fp->toffset,SEEK_SET)>0)
{
write(ar->fd,(void*)&fp->st.mtime,sizeof(time_t));
}
}
}
if (sp && sp->addr)
free(sp->addr);
if (dp)
dtclose(dp);
if(sp)
free(sp);
return 0;
}
static size_t displacement(struct Table *tp,size_t addr)
{
size_t disp = 0;
while(tp)
{
disp = tp->disp;
if(addr>tp->offset)
break;
tp = tp->next;
}
return(disp);
}
static void omfload(Ardir_t *ar,unsigned char *base, unsigned char *last, struct Table *tp, int dmars)
{
State_t *sp = (State_t*)ar->data;
unsigned char *cp=base, *end=last;
int *ip;
Arfile_t *fp;
int len;
struct Table *tpnext;
if(dmars)
{
/* string table at the top */
while(*cp)
cp += strlen((char*)cp)+1;
while(cp[4]==0)
cp++;
}
else
{
readint(cp,&len,1);
end = base + len;
}
for(ip=(int*)cp; (unsigned char*)(ip+6) < end; ip+=7)
{
if(dmars)
len = *ip;
else
readint((unsigned char*)ip,&len,1);
if(base+len >= last)
break;
if(!(fp = ar_getnode(ar,(char*)base+len)))
return;
fp->st.mtime = (time_t)ip[1];
fp->st.mode = (mode_t)ip[2];
fp->st.uid = (uid_t)ip[3];
fp->st.gid = (gid_t)ip[4];
memcpy(fp->suffix,&ip[5],sizeof(fp->suffix));
fp->toffset = ((char*)&ip[1])-(char*)(sp->addr);
fp->toffset += displacement(tp,((unsigned char*)&ip[1])-base);
if(ip[6])
fp->alias = (char*)base+ip[6];
}
while(tp)
{
tpnext = tp->next;
free((void*)tp);
tp = tpnext;
}
}
/*
* openf
*/
static int
omfopen(Ardir_t* ar, char* buf, size_t size)
{
State_t* state;
int pagesize;
unsigned char *addr, *addrstart, *addrmax, *begin,*cp, *base=0, *last;
char name[PATH_MAX];
Arfile_t *fp;
struct Table *tp=0, *tpnew;
int dmars=0,n,type,special=0,len;
if (ar->fd>=0 && (size<=0 || *((unsigned char*)buf) != OMF_LIBHDR))
return -1;
if(!(state = newof(0,State_t,1,0)))
return -1;
ar->data = (void*)state;
if(!(state->dict = dtopen(&namdisc,Dtoset)))
goto nope;
if(ar->fd<0)
return 0;
size = (size_t)ar->st.st_size;
if(!(addr = (unsigned char*)malloc(size)))
goto nope;
addrstart = addr;
state->addr = (void*)addr;
if(lseek(ar->fd,(off_t)0, SEEK_SET)<0)
goto nope;
if(read(ar->fd,(void*)addr,size) < 0)
goto nope;
addrmax=addr+size;
addr = readint(addr+1,&n,0);
pagesize = n+3;
while((addr+=n) < addrmax)
{
if(*addr==OMF_LIBDHD)
return(0);
cp = addr;
type = *addr;
addr = readint(addr+1,&n,0);
if((type&~1)==OMF_MODEND)
{
if(special)
{
if(base)
omfload(ar,base,last,tp,dmars);
special = 0;
}
else
{
if(!(fp = ar_getnode(ar,name)))
return(0);
fp->st.offset = begin-addrstart;
fp->st.size = addr+n-begin;
}
addr +=n;
addr = addrstart + round(addr-addrstart,pagesize);
n = 0;
}
else if(type==OMF_THEADR)
{
if(memcmp(addr+1,FILENAME,sizeof(FILENAME)-2))
{
begin = addr+1;
len = *addr;
if(addr[1]=='.' && addr[2]=='\\')
{
len -=2;
begin +=2;
}
memcpy(name,begin,len);
name[len] = 0;
begin = cp;
}
else
special = 1;
}
else if((type&~1)==OMF_LEDATA && special)
{
int offset;
cp = readindex(addr,&len);
cp= readint(cp,&offset,type&1);
dmars = (type&1);
len = (n-1) - (cp-addr);
if(!(tpnew = newof(0,struct Table,1,0)))
return(0);
tpnew->next = tp;
tp = tpnew;
if(!base)
base = last = cp;
else
{
tp->disp = cp - (base+offset);
memcpy(base+offset,cp,len);
}
tp->offset = offset;
last += len;
}
}
nope:
omfclose(ar);
return -1;
}
/*
* nextf
*/
static Ardirent_t*
omfnext(Ardir_t* ar)
{
State_t *ap = (State_t*)ar->data;
Arfile_t *fp;
if(ap->next)
ap->next = (Arfile_t*)dtnext(ap->dict,ap->next);
else
{
dtdisc(ap->dict, &offdisc, 0);
ap->next = (Arfile_t*)dtfirst(ap->dict);
}
if(!(fp = ap->next))
return(0);
if(*fp->suffix)
{
char *last = strrchr(fp->st.name,'.');
if(last)
last++;
else
last = fp->st.name+strlen(fp->st.name);
memcpy((void*)last,(void*)fp->suffix,sizeof(fp->suffix));
}
if(!(ar->flags&ARDIR_FORCE) && fp->alias)
fp->st.name = fp->alias;
return(&fp->st);
}
/*
* returns -1 for error
* returns 0 for ignore
* returns ARDIR_CREATE add
* returns ARDIR_REPLACE replace
* returns ARDIR_DELETE delete
*/
int omfinsert(Ardir_t *ar, const char *name, int op)
{
char *suffix,fname[256];
Dt_t *dp = ((State_t*)ar->data)->dict;
int m,n,fd;
Arfile_t *fp;
struct stat statb;
int ret = -1;
if(suffix=strrchr(name,'.'))
n = (const char*)++suffix - name;
else
n = strlen(name);
if((fd=open(name,O_RDONLY|O_cloexec))>=0)
{
if(fstat(fd,&statb)>=0 && (m=is_omf(fd)))
{
read(fd,(void*)fname,m);
fname[m] = 0;
m = memcmp((void*)fname,(void*)name,n);
ret = ARDIR_CREATE;
}
close(fd);
}
fp = (Arfile_t*)dtmatch(dp,(void*)fname);
if(ret<0 && !((op&ARDIR_DELETE) && fp))
return -1;
if(fp)
{
if(op&ARDIR_DELETE)
{
dtdelete(dp,(Void_t*)fp);
return ARDIR_DELETE;
}
if(fp->st.mtime>= statb.st_mtime && (op&ARDIR_NEWER))
return 0 ;
ret = ARDIR_REPLACE;
}
else
{
if(op&ARDIR_DELETE)
return -1 ;
if(!(fp = (Arfile_t*)ar_getnode(ar,fname)))
return -1 ;
}
fp->st.mode = statb.st_mode&(S_IRWXU|S_IRWXG|S_IRWXO);
fp->st.uid = statb.st_uid;
fp->st.gid = statb.st_gid;
fp->st.mtime = statb.st_mtime;
fp->st.size = (size_t)statb.st_size;
fp->st.offset = ++ar->st.st_size;
if(m)
fp->alias = (char*)name;
if(suffix)
memcpy(fp->suffix,suffix,sizeof(fp->suffix));
return(ret);
}
const char *omfspecial(Ardir_t *ar)
{
return(FILENAME);
}
/*
* changef
*/
static int
omfchange(Ardir_t* ar, Ardirent_t* ent)
{
State_t *sp = (State_t*)ar->data;
Arfile_t *fp = (Arfile_t*)ent;
fp->flags = 1;
sp->state = 1;
return 0;
}
Ardirmeth_t ar_omf =
{
"omf",
"omf archive",
omfopen,
omfnext,
omfchange,
omfinsert,
omfspecial,
omfclose,
ar_omf_next
};

View file

@ -1,165 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* pdp11 archive format method
*/
#include <ardirlib.h>
#include <swap.h>
#include <tm.h>
#define MAGIC 0177545
#define MAGIC_SIZE 2
typedef struct Header_s
{
char ar_name[14];
uint32_t ar_date; /* native representation*/
char ar_uid; /* " */
char ar_gid; /* " */
uint16_t ar_mode; /* " */
uint32_t ar_size; /* " */
} Header_t;
typedef struct State_s /* method state */
{
off_t current; /* current dirent offset */
off_t offset; /* next dirent offset */
int swap; /* swapget() op if necessary */
Header_t header; /* current header */
char name[15]; /* ar_name with trailing '\0' */
} State_t;
/*
* closef
*/
static int
pdpclose(Ardir_t* ar)
{
State_t* state;
if (ar && (state = (State_t*)ar->data))
free(state);
return 0;
}
/*
* openf
*/
static int
pdpopen(Ardir_t* ar, char* buf, size_t n)
{
int swap;
State_t* state;
if (n <= MAGIC_SIZE)
return -1;
if (swapget(0, buf, MAGIC_SIZE) == MAGIC)
swap = 0;
else if (swapget(1, buf, MAGIC_SIZE) == MAGIC)
swap = 3;
else
return -1;
if (!(state = newof(0, State_t, 1, 0)))
return -1;
ar->data = (void*)state;
state->swap = swap;
state->offset = MAGIC_SIZE;
ar->truncate = 14;
return 0;
}
/*
* nextf
*/
static Ardirent_t*
pdpnext(Ardir_t* ar)
{
State_t* state = (State_t*)ar->data;
ssize_t z;
state->current = state->offset;
if (lseek(ar->fd, state->offset, SEEK_SET) != state->offset)
{
ar->error = errno;
return 0;
}
if (read(ar->fd, (char*)&state->header, sizeof(state->header)) != sizeof(state->header))
{
if ((z = read(ar->fd, (char*)&state->header, 1)) < 0)
ar->error = errno;
else if (z > 0)
ar->error = EINVAL;
return 0;
}
strncpy(ar->dirent.name = state->name, state->header.ar_name, sizeof(state->header.ar_name));
ar->dirent.mtime = swapget(state->swap, (char*)&state->header.ar_date, sizeof(state->header.ar_date));
ar->dirent.uid = swapget(state->swap, (char*)&state->header.ar_uid, sizeof(state->header.ar_uid));
ar->dirent.gid = swapget(state->swap, (char*)&state->header.ar_gid, sizeof(state->header.ar_gid));
ar->dirent.mode = swapget(state->swap, (char*)&state->header.ar_mode, sizeof(state->header.ar_mode));
ar->dirent.offset = state->offset += sizeof(state->header);
ar->dirent.size = swapget(state->swap, (char*)&state->header.ar_size, sizeof(state->header.ar_size));
state->offset += ar->dirent.size + (ar->dirent.size & 01);
return &ar->dirent;
}
/*
* changef
*/
static int
pdpchange(Ardir_t* ar, Ardirent_t* ent)
{
State_t* state = (State_t*)ar->data;
off_t o;
o = state->current + offsetof(Header_t, ar_date);
if (lseek(ar->fd, o, SEEK_SET) != o)
{
ar->error = errno;
return -1;
}
swapput(state->swap, (char*)&state->header.ar_date, sizeof(state->header.ar_date), (intmax_t)ent->mtime);
if (write(ar->fd, &state->header.ar_date, sizeof(state->header.ar_date)) != sizeof(state->header.ar_date))
{
ar->error = errno;
return -1;
}
return 0;
}
Ardirmeth_t ar_pdp11 =
{
"pdp11",
"pdp11 archive",
pdpopen,
pdpnext,
pdpchange,
0,
0,
pdpclose,
ar_pdp11_next
};

View file

@ -1,375 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* portable archive format method
*/
#include <ardirlib.h>
#include <ctype.h>
#include <tm.h>
#define MAGIC "!<arch>\n"
#define MAGIC_SIZE 8
#define TERM_port '/'
#define FMAG_port_0 '`'
#define FMAG_port_1 '\n'
#define SYMDIR_port "(/[!/]|_______[0-9_][0-9_][0-9_]E[BL]E[BL]_)*"
#define SYMDIR_other "(._|_.|__.|___)*"
#define SYMDIR_age 5
#define TERM_rand ' '
#define SYMDIR_rand "(__.SYMDEF|__________E\?\?\?X)*"
#define SYMDIR_strict "__.SYMDEF SORTED*"
typedef struct Header_s
{
char ar_name[16];
char ar_date[12]; /* left-adj; decimal char*; blank fill */
char ar_uid[6]; /* " */
char ar_gid[6]; /* " */
char ar_mode[8]; /* left-adj; octal char*; blank fill */
char ar_size[10]; /* left-adj; decimal char*; blank fill */
char ar_fmag[2]; /* FMAG_port_[01] */
} Header_t;
typedef struct State_s /* method state */
{
off_t current; /* current dirent offset */
off_t offset; /* next dirent offset */
off_t patch; /* symdir time patch offset */
char* names; /* long name table */
char* name; /* local long name */
int size; /* local long name max size */
int touch; /* touch symbol table time */
int separator; /* alternate path separator */
Header_t header; /* current header */
char term[1]; /* trailing '\0' for header */
} State_t;
/*
* closef
*/
static int
portclose(Ardir_t* ar)
{
State_t* state;
int r;
char buf[sizeof(state->header.ar_date) + 1];
if (!ar || !(state = (State_t*)ar->data))
r = -1;
else
{
r = 0;
if (state->touch && state->patch >= 0)
{
if (lseek(ar->fd, state->patch, SEEK_SET) != state->patch)
r = -1;
else
{
sfsprintf(buf, sizeof(buf), "%-*lu", sizeof(buf) - 1, (unsigned long)time((time_t*)0) + 5);
if (write(ar->fd, buf, sizeof(buf) - 1) != (sizeof(buf) - 1))
r = -1;
}
}
if (state->names)
free(state->names);
if (state->name)
free(state->name);
free(state);
}
return r;
}
/*
* openf
*/
static int
portopen(Ardir_t* ar, char* buf, size_t n)
{
long size;
size_t i;
Header_t* hdr;
State_t* state;
char* name;
char* e;
if (n < (MAGIC_SIZE + sizeof(Header_t)))
return -1;
if (memcmp(buf, MAGIC, MAGIC_SIZE))
return -1;
/*
* check for a symbol directory
*/
hdr = (Header_t*)(buf + MAGIC_SIZE);
if (hdr->ar_fmag[0] != FMAG_port_0 || hdr->ar_fmag[1] != FMAG_port_1)
return -1;
#if __pdp11__ || pdp11
ar->error = ENOSYS;
return -1;
#else
if (!(state = newof(0, State_t, 1, 0)))
return -1;
ar->data = (void*)state;
state->offset = MAGIC_SIZE;
ar->truncate = 14;
name = hdr->ar_name;
if (name[0] == '#' && name[1] == '1' && name[2] == TERM_port)
{
i = strtol(name + 3, NiL, 10);
if (n < (MAGIC_SIZE + sizeof(Header_t) + i))
return -1;
name = (char*)(hdr + 1);
ar->truncate = 0;
}
if (strmatch(name, SYMDIR_port) || strmatch(name, SYMDIR_rand) && (ar->flags |= ARDIR_RANLIB))
{
if (sfsscanf(hdr->ar_size, "%ld", &size) != 1)
goto nope;
state->patch = MAGIC_SIZE + offsetof(Header_t, ar_date);
state->offset += sizeof(Header_t) + size + (size & 01);
if ((ar->flags & ARDIR_RANLIB) && (sfsscanf(hdr->ar_date, "%lu", &ar->symtime) != 1 || (unsigned long)ar->st.st_mtime > ar->symtime + (strmatch(name, SYMDIR_strict) ? 0 : SYMDIR_age)))
ar->symtime = 0;
if (!(ar->flags & ARDIR_RANLIB) && hdr->ar_uid[0] == ' ' && hdr->ar_gid[0] == ' ')
state->separator = '\\';
}
else
{
/*
* there is no symbol directory
*/
state->patch = -1;
hdr->ar_date[0] = 0;
if (strchr(name, TERM_port) && strmatch(name, SYMDIR_other))
ar->flags &= ~ARDIR_RANLIB;
else
ar->flags |= ARDIR_RANLIB;
}
if (lseek(ar->fd, state->offset, SEEK_SET) < 0)
goto nope;
hdr = &state->header;
while (read(ar->fd, (char*)hdr, sizeof(state->header)) == sizeof(state->header) && hdr->ar_name[0] == TERM_port)
{
if (sfsscanf(hdr->ar_size, "%ld", &size) != 1)
goto nope;
size += (size & 01);
if (!state->names && hdr->ar_name[1] == TERM_port && (hdr->ar_name[2] == ' ' || hdr->ar_name[2] == TERM_port && hdr->ar_name[3] == ' '))
{
/*
* long name string table
*/
if (!(state->names = newof(0, char, size, 0)) || read(ar->fd, state->names, size) != size)
goto nope;
ar->truncate = 0;
if (hdr->ar_name[1] == TERM_port)
for (e = (name = state->names) + size; name < e; name++)
if (*name == TERM_port && *(name + 1) == '\n')
*name = 0;
}
else if (isdigit(hdr->ar_name[1]))
break;
else if (lseek(ar->fd, (off_t)size, SEEK_CUR) < 0)
goto nope;
state->offset += sizeof(state->header) + size;
}
return 0;
#endif
nope:
portclose(ar);
return -1;
}
/*
* hpux 32 bit uid/gid workaround
*/
static int
ar_uid_gid(Ardir_t* ar, char* b, long* p)
{
int i;
long n;
if (b[5] != ' ')
{
n = 0;
for (i = 0; i < 5; i++)
{
n <<= 6;
n |= b[i] - ' ';
}
n <<= 2;
n |= b[i] - '@';
*p = n;
error(-1, "AHA ar_uid_gid '%s' => %lu\n", b, n);
}
else if (sfsscanf(b, "%ld", p) != 1)
{
ar->error = EINVAL;
return -1;
}
return 0;
}
/*
* nextf
*/
static Ardirent_t*
portnext(Ardir_t* ar)
{
State_t* state = (State_t*)ar->data;
long n;
ssize_t z;
char* s;
state->current = state->offset;
if (lseek(ar->fd, state->offset, SEEK_SET) != state->offset)
{
ar->error = errno;
return 0;
}
if (read(ar->fd, (char*)&state->header, sizeof(state->header)) != sizeof(state->header))
{
if ((z = read(ar->fd, (char*)&state->header, 1)) < 0)
ar->error = errno;
else if (z > 0)
ar->error = EINVAL;
return 0;
}
if (state->header.ar_fmag[0] != FMAG_port_0 || state->header.ar_fmag[1] != FMAG_port_1)
{
ar->error = EINVAL;
return 0;
}
if (sfsscanf(state->header.ar_date, "%ld", &n) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.mtime = n;
ar->dirent.name = state->header.ar_name;
ar->dirent.name[sizeof(state->header.ar_name)] = 0;
if (state->names && (*ar->dirent.name == TERM_port || *ar->dirent.name == ' '))
ar->dirent.name = state->names + strtol(ar->dirent.name + 1, NiL, 10);
if (ar_uid_gid(ar, state->header.ar_uid, &n))
return 0;
ar->dirent.uid = n;
if (ar_uid_gid(ar, state->header.ar_gid, &n))
return 0;
ar->dirent.gid = n;
if (sfsscanf(state->header.ar_mode, "%lo", &n) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.mode = n;
if (sfsscanf(state->header.ar_size, "%ld", &n) != 1)
{
ar->error = EINVAL;
return 0;
}
ar->dirent.offset = state->offset += sizeof(state->header);
ar->dirent.size = n;
state->offset += n + (n & 01);
if (ar->dirent.name[0] == '#' && ar->dirent.name[1] == '1' && ar->dirent.name[2] == TERM_port)
{
n = strtol(ar->dirent.name + 3, NiL, 10);
ar->dirent.size -= n;
if ((n + 1) >= state->size)
{
state->size = roundof(n + 1, 128);
if (!(state->name = newof(state->name, char, state->size, 0)))
{
ar->error = ENOMEM;
return 0;
}
}
if ((z = read(ar->fd, state->name, n)) < 0)
{
ar->error = errno;
return 0;
}
else if (z != n)
{
ar->error = EINVAL;
return 0;
}
state->name[n] = 0;
ar->dirent.name = state->name;
}
else
{
for (s = ar->dirent.name + strlen(ar->dirent.name); s > ar->dirent.name && (*(s - 1) == TERM_port || *(s - 1) == TERM_rand); s--);
*s = 0;
}
if (state->separator)
for (s = ar->dirent.name; s = strchr(s, state->separator); *s++ = '/');
return &ar->dirent;
}
/*
* changef
*/
static int
portchange(Ardir_t* ar, Ardirent_t* ent)
{
State_t* state = (State_t*)ar->data;
off_t o;
char buf[sizeof(state->header.ar_date) + 1];
o = state->current + offsetof(Header_t, ar_date);
if (lseek(ar->fd, o, SEEK_SET) != o)
{
ar->error = errno;
return -1;
}
sfsprintf(buf, sizeof(buf), "%-*lu", sizeof(buf) - 1, (unsigned long)ent->mtime);
if (write(ar->fd, buf, sizeof(buf) - 1) != (sizeof(buf) - 1))
{
ar->error = errno;
return -1;
}
state->touch = 1;
return 0;
}
Ardirmeth_t ar_port =
{
"portable",
"portable archive",
portopen,
portnext,
portchange,
0,
0,
portclose,
ar_port_next
};

View file

@ -1,196 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* s5r0 archive format method
*/
#include <ardirlib.h>
#include <swap.h>
#include <tm.h>
#define MAGIC "<ar>"
#define MAGIC_SIZE 4
typedef struct Header_s
{
char ar_magic[MAGIC_SIZE]; /* MAGIC */
char ar_name[16];
char ar_date[4]; /* swapget() accessed */
char ar_syms[4]; /* " */
} Header_t;
typedef struct Member_s
{
char arf_name[16];
char arf_date[4]; /* swapget() accessed */
char arf_uid[4]; /* " */
char arf_gid[4]; /* " */
char arf_mode[4]; /* " */
char arf_size[4]; /* " */
} Member_t;
typedef struct Symbol_s
{
char sym_name[8]; /* ' ' terminated */
char sym_ptr[4]; /* swapget() accessed */
} Symbol_t;
typedef struct State_s /* method state */
{
off_t current; /* current dirent offset */
off_t offset; /* next dirent offset */
off_t patch; /* symdir time patch offset */
int swap; /* swapget() op if necessary */
int touch; /* touch symbol table time */
Member_t member; /* current member */
} State_t;
/*
* closef
*/
static int
s5r0close(Ardir_t* ar)
{
State_t* state;
int r;
Header_t header;
if (!ar || !(state = (State_t*)ar->data))
r = -1;
else
{
r = 0;
if (state->touch && state->patch >= 0)
{
if (lseek(ar->fd, state->patch, SEEK_SET) != state->patch)
r = -1;
else
{
swapput(0, (char*)&header.ar_date, sizeof(header.ar_date), (intmax_t)((unsigned long)time((time_t*)0) + 5));
if (write(ar->fd, &header.ar_date, sizeof(header.ar_date)) != sizeof(header.ar_date))
r = -1;
}
}
free(state);
}
return r;
}
/*
* openf
*/
static int
s5r0open(Ardir_t* ar, char* buf, size_t n)
{
Header_t* hdr;
State_t* state;
if (n <= sizeof(Header_t))
return -1;
hdr = (Header_t*)buf;
if (memcmp(hdr->ar_magic, MAGIC, MAGIC_SIZE))
return -1;
if (!(state = newof(0, State_t, 1, 0)))
return -1;
ar->data = (void*)state;
state->patch = offsetof(Header_t, ar_date);
state->offset = sizeof(Header_t) + swapget(0, hdr->ar_syms, sizeof(hdr->ar_syms)) * sizeof(Symbol_t);
ar->truncate = 15;
return 0;
}
/*
* nextf
*/
static Ardirent_t*
s5r0next(Ardir_t* ar)
{
State_t* state = (State_t*)ar->data;
ssize_t z;
state->current = state->offset;
if (lseek(ar->fd, state->offset, SEEK_SET) != state->offset)
{
ar->error = errno;
return 0;
}
if (read(ar->fd, (char*)&state->member, sizeof(state->member)) != sizeof(state->member))
{
if ((z = read(ar->fd, (char*)&state->member, 1)) < 0)
ar->error = errno;
else if (z > 0)
ar->error = EINVAL;
return 0;
}
ar->dirent.name = state->member.arf_name;
ar->dirent.mtime = swapget(0, (char*)&state->member.arf_date, sizeof(state->member.arf_date));
ar->dirent.uid = swapget(0, (char*)&state->member.arf_uid, sizeof(state->member.arf_uid));
ar->dirent.gid = swapget(0, (char*)&state->member.arf_gid, sizeof(state->member.arf_gid));
ar->dirent.mode = swapget(0, (char*)&state->member.arf_mode, sizeof(state->member.arf_mode));
ar->dirent.offset = state->offset += sizeof(state->member);
ar->dirent.size = swapget(0, (char*)&state->member.arf_size, sizeof(state->member.arf_size));
state->offset += ar->dirent.size + (ar->dirent.size & 01);
return &ar->dirent;
}
/*
* changef
*/
static int
s5r0change(Ardir_t* ar, Ardirent_t* ent)
{
State_t* state = (State_t*)ar->data;
off_t o;
o = state->current + offsetof(Member_t, arf_date);
if (lseek(ar->fd, o, SEEK_SET) != o)
{
ar->error = errno;
return -1;
}
swapput(0, (char*)&state->member.arf_date, sizeof(state->member.arf_date), (intmax_t)ent->mtime);
if (write(ar->fd, &state->member.arf_date, sizeof(state->member.arf_date)) != sizeof(state->member.arf_date))
{
ar->error = errno;
return -1;
}
state->touch = 1;
return 0;
}
Ardirmeth_t ar_s5r0 =
{
"s5r0",
"system V release 0 archive",
s5r0open,
s5r0next,
s5r0change,
0,
0,
s5r0close,
ar_s5r0_next
};

View file

@ -1,188 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* archive scan/touch/extract implementation
*/
#include <ardirlib.h>
Ardir_t*
ardiropen(const char* file, Ardirmeth_t* meth, int flags)
{
Ardir_t* ar;
char* skip;
off_t pos;
ssize_t n = 0;
char buf[1024];
if (!(ar = newof(0, Ardir_t, 1, strlen(file) + 1)))
return 0;
strcpy(ar->path = (char*)(ar + 1), file);
ar->flags = flags;
if (((ar->fd = open(file, (flags & ARDIR_CREATE) ? (O_CREAT|O_TRUNC|O_RDWR|O_BINARY|O_cloexec) : (flags & ARDIR_UPDATE) ? (O_RDWR|O_BINARY|O_cloexec) : (O_RDONLY|O_BINARY|O_cloexec))) < 0 || fstat(ar->fd, &ar->st) || !S_ISREG(ar->st.st_mode)) && (!meth || !(flags & ARDIR_FORCE)))
{
ardirclose(ar);
return 0;
}
if (ar->fd >= 0 && ((pos = lseek(ar->fd, (off_t)0, SEEK_CUR)) < 0 || (n = read(ar->fd, buf, sizeof(buf))) < 0 || lseek(ar->fd, pos, SEEK_SET) != pos))
{
ardirclose(ar);
return 0;
}
if (!(ar->meth = meth))
{
skip = getenv("_AST_DEBUG_ARDIR_SKIP");
for (meth = ar_first_method; ar->meth = meth; meth = meth->next)
if ((!skip || !strmatch(meth->name, skip)) && !(*meth->openf)(ar, buf, n))
break;
if (!(ar->meth = meth))
{
ardirclose(ar);
return 0;
}
}
else if ((*meth->openf)(ar, buf, n))
{
ardirclose(ar);
return 0;
}
return ar;
}
Ardirent_t*
ardirnext(Ardir_t* ar)
{
return (ar->meth && ar->meth->nextf) ? (*ar->meth->nextf)(ar) : (Ardirent_t*)0;
}
off_t
ardircopy(Ardir_t* ar, Ardirent_t* ent, int fd)
{
ssize_t n;
size_t m;
off_t z;
off_t pos;
char buf[1024 * 16];
if (ent->offset < 0)
{
ar->error = ENOSYS;
return -1;
}
pos = lseek(ar->fd, (off_t)0, SEEK_CUR);
if (lseek(ar->fd, ent->offset, SEEK_SET) != ent->offset)
return -1;
z = ent->size;
while (z > 0)
{
m = z > sizeof(buf) ? sizeof(buf) : z;
if ((n = read(ar->fd, buf, m)) < 0)
{
ar->error = errno;
break;
}
if (n == 0)
break;
if (write(fd, buf, n) != n)
{
ar->error = errno;
break;
}
z -= n;
}
lseek(ar->fd, pos, SEEK_SET);
if (z)
{
errno = EIO;
z = -z;
}
else
z = ent->size;
return z;
}
int
ardirchange(Ardir_t* ar, Ardirent_t* ent)
{
if (!ar->meth || !ar->meth->changef)
{
ar->error = EINVAL;
return -1;
}
return (*ar->meth->changef)(ar, ent);
}
int
ardirinsert(Ardir_t* ar, const char* name, int flags)
{
if (!ar->meth || !ar->meth->insertf)
{
ar->error = EINVAL;
return -1;
}
return (*ar->meth->insertf)(ar, name, flags);
}
const char*
ardirspecial(Ardir_t* ar)
{
if (!ar->meth || !ar->meth->specialf)
{
ar->error = EINVAL;
return 0;
}
return (*ar->meth->specialf)(ar);
}
int
ardirclose(Ardir_t* ar)
{
int r;
if (!ar)
return -1;
r = (ar->meth && ar->meth->closef) ? (*ar->meth->closef)(ar) : -1;
if (ar->error)
r = -1;
if (ar->fd >= 0)
close(ar->fd);
free(ar);
return r;
}
Ardirmeth_t*
ardirmeth(const char* name)
{
Ardirmeth_t* meth;
for (meth = ar_first_method; meth; meth = meth->next)
if (!strcasecmp(name, meth->name))
return meth;
return 0;
}
Ardirmeth_t*
ardirlist(Ardirmeth_t* meth)
{
return meth ? meth->next : ar_first_method;
}

View file

@ -1,110 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* archive scan/touch/extract interface
*/
#ifndef _ARDIR_H
#define _ARDIR_H 1
#include <ast.h>
#include <ls.h>
#define ARDIR_VERSION 20020501L
/*
* retain this order!
*/
#define ARDIR_CREATE 0x0001
#define ARDIR_DELETE 0x0002
#define ARDIR_REPLACE (ARDIR_CREATE|ARDIR_DELETE)
#define ARDIR_FORCE 0x0004
#define ARDIR_LOCAL 0x0008
#define ARDIR_NEWER 0x0010
#define ARDIR_OUTOFDATE 0x0020
#define ARDIR_RANLIB 0x0040
#define ARDIR_SEQUENTIAL 0x0080
#define ARDIR_UPDATE 0x0100
struct Ardir_s; typedef struct Ardir_s Ardir_t;
struct Ardirent_s; typedef struct Ardirent_s Ardirent_t;
struct Ardirmeth_s; typedef struct Ardirmeth_s Ardirmeth_t;
struct Ardirmeth_s
{
const char* name;
const char* description;
int (*openf)(Ardir_t*, char*, size_t);
Ardirent_t* (*nextf)(Ardir_t*);
int (*changef)(Ardir_t*, Ardirent_t*);
int (*insertf)(Ardir_t*, const char*, int);
const char* (*specialf)(Ardir_t*);
int (*closef)(Ardir_t*);
Ardirmeth_t* next;
};
struct Ardirent_s
{
char* name;
time_t mtime;
off_t offset;
off_t size;
uid_t uid;
gid_t gid;
mode_t mode;
#ifdef _ARDIRENT_PRIVATE_
_ARDIRENT_PRIVATE_
#endif
};
struct Ardir_s
{
unsigned long version;
char* path;
struct stat st;
unsigned long symtime;
Ardirmeth_t* meth;
void* data;
unsigned int flags;
int error;
int fd;
int truncate;
Ardirent_t dirent;
#ifdef _ARDIR_PRIVATE_
_ARDIR_PRIVATE_
#endif
};
extern Ardirmeth_t* ardirmeth(const char*);
extern Ardirmeth_t* ardirlist(Ardirmeth_t*);
extern Ardir_t* ardiropen(const char*, Ardirmeth_t*, int);
extern Ardirent_t* ardirnext(Ardir_t*);
extern off_t ardircopy(Ardir_t*, Ardirent_t*, int);
extern int ardirchange(Ardir_t*, Ardirent_t*);
extern int ardirinsert(Ardir_t*, const char*, int);
extern const char* ardirspecial(Ardir_t*);
extern int ardirclose(Ardir_t*);
#endif

View file

@ -1,58 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
/*
* archive scan/touch/extract implementation definitions
*/
#ifndef _ARDIRLIB_H
#define _ARDIRLIB_H 1
#include <ast.h>
#include <ardir.h>
#include <error.h>
#define ar_first_method (&ar_omf)
#define ar_aix_next (&ar_aixbig)
#define ar_aixbig_next (&ar_local)
#define ar_local_next (0)
#define ar_omf_next (&ar_pdp11)
#define ar_pdp11_next (&ar_s5r0)
#define ar_port_next (&ar_aix)
#define ar_s5r0_next (&ar_port)
#define ar_aix _ar_aix
#define ar_aixbig _ar_aixbig
#define ar_local _ar_local
#define ar_omf _ar_omf
#define ar_pdp11 _ar_pdp11
#define ar_port _ar_port
#define ar_s5r0 _ar_s5r0
extern Ardirmeth_t ar_aix;
extern Ardirmeth_t ar_aixbig;
extern Ardirmeth_t ar_local;
extern Ardirmeth_t ar_omf;
extern Ardirmeth_t ar_pdp11;
extern Ardirmeth_t ar_port;
extern Ardirmeth_t ar_s5r0;
#endif

View file

@ -1,67 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
/**************************
* Record types:
*/
#define OMF_RHEADR 0x6E
#define OMF_REGINT 0x70
#define OMF_REDATA 0x72
#define OMF_RIDATA 0x74
#define OMF_OVLDEF 0x76
#define OMF_ENDREC 0x78
#define OMF_BLKDEF 0x7A
#define OMF_BLKEND 0x7C
#define OMF_DEBSYM 0x7E
#define OMF_THEADR 0x80
#define OMF_LHEADR 0x82
#define OMF_PEDATA 0x84
#define OMF_PIDATA 0x86
#define OMF_COMENT 0x88
#define OMF_MODEND 0x8A
#define OMF_EXTDEF 0x8C
#define OMF_TYPDEF 0x8E
#define OMF_PUBDEF 0x90
#define OMF_LOCSYM 0x92
#define OMF_LINNUM 0x94
#define OMF_LNAMES 0x96
#define OMF_SEGDEF 0x98
#define OMF_GRPDEF 0x9A
#define OMF_FIXUPP 0x9C
#define OMF_LEDATA 0xA0
#define OMF_LIDATA 0xA2
#define OMF_LIBHED 0xA4
#define OMF_LIBNAM 0xA6
#define OMF_LIBLOC 0xA8
#define OMF_LIBDIC 0xAA
#define OMF_COMDEF 0xB0
#define OMF_LEXTDEF 0xB4
#define OMF_LPUBDEF 0xB6
#define OMF_LCOMDEF 0xB8
#define OMF_CEXTDEF 0xBC
#define OMF_COMDAT 0xC2
#define OMF_LINSYM 0xC4
#define OMF_ALIAS 0xC6
#define OMF_NBKPAT 0xC8
#define OMF_LLNAMES 0xCA
#define OMF_LIBHDR 0xf0 /* library header */
#define OMF_LIBDHD 0xf1 /* library dictionary header */

View file

@ -1,58 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2002-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#include <ast.h>
#include <ardir.h>
#include <error.h>
main(int argc, char** argv)
{
Ardir_t* dir;
Ardirent_t* ent;
long touch;
char* file;
touch = 0;
while (file = *++argv)
{
if (!strcmp(file, "-t") && *(argv + 1))
touch = strtol(*++argv, NiL, 0);
else if (dir = ardiropen(file, NiL, touch ? ARDIR_UPDATE : 0))
{
sfprintf(sfstdout, "%s: type=%s truncate=%d%s\n", file, dir->meth->name, dir->truncate, (dir->flags & ARDIR_RANLIB) ? " ranlib" : "");
while (ent = ardirnext(dir))
{
if (touch)
{
ent->mtime = touch;
ardirchange(dir, ent);
sfprintf(sfstdout, "touch %s\n", ent->name);
}
else
sfprintf(sfstdout, "%s %8u %8u %8llu %8llu %s %s\n", fmtmode(ent->mode, 1), ent->uid, ent->gid, ent->size, ent->offset, fmttime("%k", ent->mtime), ent->name);
}
if (ardirclose(dir))
error(2, "%s: archive read error", file);
}
else
error(ERROR_SYSTEM|2, "%s: not an archive", file);
}
return 0;
}

View file

@ -1,46 +0,0 @@
license=(
type=special
package=bzip
author="Julian R Seward <jseward@acm.org>"
since=1996
notice='
This program, "bzip2" and associated library "libbzip2", are
copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0 of 28 June 1998'
)

View file

@ -1,15 +0,0 @@
:PACKAGE: ast
LICENSE = zlib,since=1996,author="Julian R Seward"
CCFLAGS = $(CC.OPTIMIZE) $(CC.DLL)
bz 2.0 :LIBRARY: bzlib.h bzlib_private.h sfdcbzip.h \
blocksort.c huffman.c crctable.c randtable.c compress.c \
decompress.c bzlib.c sfdcbzip.c
"win32*" :NOOPTIMIZE: blocksort.c
$(INCLUDEDIR) :INSTALLPROTO: sfdcbzip.h bzlib.h
:: LICENSE README RELEASE

View file

@ -1,285 +0,0 @@
info mam static 00000 1994-07-17 make (AT&T Research) 5.7 2012-06-20
setv INSTALLROOT ../../..
setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast
setv PACKAGE_ast_LIB ${INSTALLROOT}/lib
setv PACKAGEROOT ../../../../..
setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS}
setv ARFLAGS rc
setv AS as
setv ASFLAGS
setv CC cc
setv mam_cc_FLAGS ${mam_cc_DLL}
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
setv COTEMP $$
setv CPIO cpio
setv CPIOFLAGS
setv CPP "${CC} -E"
setv F77 f77
setv HOSTCC ${CC}
setv IGNORE
setv LD ld
setv LDFLAGS
setv LEX lex
setv LEXFLAGS
setv LPR lpr
setv LPRFLAGS
setv M4FLAGS
setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
setv SHELL /bin/sh
setv SILENT
setv TAR tar
setv YACC yacc
setv YACCFLAGS -d
make ${PACKAGEROOT}/lib/package/zlib.lic
done ${PACKAGEROOT}/lib/package/zlib.lic
make install
make bz
make libbz.a archive
make bz.req
exec - set -
exec - echo 'int main(){return 0;}' > 1.${COTEMP}.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -c 1.${COTEMP}.c &&
exec - x=`${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l'*' 2>&1 | sed -e 's/[][()+@?]/#/g' || :` &&
exec - {
exec - case "" in
exec - *?) echo " " ;;
exec - esac
exec - for i in bz ast
exec - do case $i in
exec - "bz"|bz)
exec - ;;
exec - *) if test -f ${INSTALLROOT}/lib/lib/$i
exec - then y=`cat ${INSTALLROOT}/lib/lib/$i`
exec - case $y in
exec - *-?*) echo "" $y ;;
exec - esac
exec - continue
exec - elif test ! -f ${INSTALLROOT}/lib/lib$i.a
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) continue ;;
exec - esac
exec - ;;
exec - esac
exec - fi
exec - ;;
exec - esac
exec - echo " -l$i"
exec - done
exec - } > bz.req
exec - rm -f 1.${COTEMP}.*
done bz.req generated
make blocksort.o
make blocksort.c
make bzhdr.h implicit
make bzlib.h implicit
make windows.h implicit
done windows.h dontcare virtual
make ${PACKAGE_ast_INCLUDE}/stdio.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit
make ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio_s.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
make ${PACKAGE_ast_INCLUDE}/regex.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_api.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
make ${PACKAGE_ast_INCLUDE}/wctype.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit
make ${PACKAGE_ast_INCLUDE}/endian.h implicit
make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_map.h dontcare
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_common.h dontcare
done ${PACKAGE_ast_INCLUDE}/bytesex.h dontcare
done ${PACKAGE_ast_INCLUDE}/endian.h dontcare
make ${PACKAGE_ast_INCLUDE}/wchar.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
done ${PACKAGE_ast_INCLUDE}/wchar.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_wctype.h dontcare
done ${PACKAGE_ast_INCLUDE}/wctype.h dontcare
prev ${PACKAGE_ast_INCLUDE}/stdio.h implicit
prev ${PACKAGE_ast_INCLUDE}/stdio.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_wchar.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
make ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/prototyped.h dontcare
done ${PACKAGE_ast_INCLUDE}/regex.h dontcare
make ${PACKAGE_ast_INCLUDE}/getopt.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_getopt.h dontcare
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/getopt.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_botch.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_botch.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_limits.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_limits.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_fcntl.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_fs.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_fs.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_fcntl.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_sys.h implicit
prev ${PACKAGE_ast_INCLUDE}/getopt.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_sys.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_lib.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_lib.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_std.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_stdio.h dontcare
done ${PACKAGE_ast_INCLUDE}/stdio.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done bzlib.h dontcare
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev ${PACKAGE_ast_INCLUDE}/stdio.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done bzhdr.h
done blocksort.c
meta blocksort.o %.c>%.o blocksort.c blocksort
prev blocksort.c
exec - ${CC} ${mam_cc_FLAGS} ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${CCFLAGS.FORCE}?} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_bz -D_PACKAGE_ast -c blocksort.c
done blocksort.o generated
make huffman.o
make huffman.c
prev bzhdr.h implicit
done huffman.c
meta huffman.o %.c>%.o huffman.c huffman
prev huffman.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_bz -D_PACKAGE_ast -c huffman.c
done huffman.o generated
make crctable.o
make crctable.c
prev bzhdr.h implicit
done crctable.c
meta crctable.o %.c>%.o crctable.c crctable
prev crctable.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_bz -D_PACKAGE_ast -c crctable.c
done crctable.o generated
make randtable.o
make randtable.c
prev bzhdr.h implicit
done randtable.c
meta randtable.o %.c>%.o randtable.c randtable
prev randtable.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_bz -D_PACKAGE_ast -c randtable.c
done randtable.o generated
make compress.o
make compress.c
prev bzhdr.h implicit
done compress.c
meta compress.o %.c>%.o compress.c compress
prev compress.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_bz -D_PACKAGE_ast -c compress.c
done compress.o generated
make decompress.o
make decompress.c
prev bzhdr.h implicit
done decompress.c
meta decompress.o %.c>%.o decompress.c decompress
prev decompress.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_bz -D_PACKAGE_ast -c decompress.c
done decompress.o generated
make bzlib.o
make bzlib.c
make io.h implicit
done io.h dontcare virtual
prev bzhdr.h implicit
done bzlib.c
meta bzlib.o %.c>%.o bzlib.c bzlib
prev bzlib.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_bz -D_PACKAGE_ast -c bzlib.c
done bzlib.o generated
make sfdcbzip.o
make sfdcbzip.c
make sfdcbzip.h implicit
make ${PACKAGE_ast_INCLUDE}/sfdisc.h implicit
make ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
make ${PACKAGE_ast_INCLUDE}/vmalloc.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/vmalloc.h dontcare
make ${PACKAGE_ast_INCLUDE}/sfio.h implicit
prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast.h dontcare
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/sfdisc.h dontcare
done sfdcbzip.h
prev bzlib.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
make ${PACKAGE_ast_INCLUDE}/sfio_t.h implicit
prev ${PACKAGE_ast_INCLUDE}/sfio.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio_t.h
done sfdcbzip.c
meta sfdcbzip.o %.c>%.o sfdcbzip.c sfdcbzip
prev sfdcbzip.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_bz -D_PACKAGE_ast -c sfdcbzip.c
done sfdcbzip.o generated
exec - ${AR} rc libbz.a blocksort.o huffman.o crctable.o randtable.o compress.o decompress.o bzlib.o sfdcbzip.o
exec - (ranlib libbz.a) >/dev/null 2>&1 || true
done libbz.a generated
done bz virtual
prev libbz.a archive
make ${INSTALLROOT}/lib
exec - if silent test ! -d ${INSTALLROOT}/lib
exec - then mkdir -p ${INSTALLROOT}/lib
exec - fi
done ${INSTALLROOT}/lib generated
make ${INSTALLROOT}/lib/libbz.a archive
prev ${INSTALLROOT}/lib
prev libbz.a archive
exec - test '' = 'libbz.a' || ${STDCMP} 2>/dev/null -s libbz.a ${INSTALLROOT}/lib/libbz.a || { ${STDMV} ${INSTALLROOT}/lib/libbz.a ${INSTALLROOT}/lib/libbz.a.old 2>/dev/null || true; ${STDCP} libbz.a ${INSTALLROOT}/lib/libbz.a ;}
exec - (ranlib ${INSTALLROOT}/lib/libbz.a) >/dev/null 2>&1 || true
done ${INSTALLROOT}/lib/libbz.a generated
make ${INSTALLROOT}/lib/lib
exec - if silent test ! -d ${INSTALLROOT}/lib/lib
exec - then mkdir -p ${INSTALLROOT}/lib/lib
exec - fi
done ${INSTALLROOT}/lib/lib generated
make ${INSTALLROOT}/lib/lib/bz
prev ${INSTALLROOT}/lib/lib
prev bz.req
exec - test '' = 'bz.req' || ${STDCMP} 2>/dev/null -s bz.req ${INSTALLROOT}/lib/lib/bz || { ${STDMV} ${INSTALLROOT}/lib/lib/bz ${INSTALLROOT}/lib/lib/bz.old 2>/dev/null || true; ${STDCP} bz.req ${INSTALLROOT}/lib/lib/bz ;}
done ${INSTALLROOT}/lib/lib/bz generated
make ${PACKAGE_ast_INCLUDE}
exec - if silent test ! -d ${PACKAGE_ast_INCLUDE}
exec - then mkdir -p ${PACKAGE_ast_INCLUDE}
exec - fi
done ${PACKAGE_ast_INCLUDE} generated
make ${PACKAGE_ast_INCLUDE}/sfdcbzip.h
prev ${PACKAGE_ast_INCLUDE}
prev sfdcbzip.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/zlib.lic '-o zlib,since=1996,author="Julian R Seward"' sfdcbzip.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/sfdcbzip.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/sfdcbzip.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/sfdcbzip.h generated
make ${PACKAGE_ast_INCLUDE}/bzlib.h
prev bzlib.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/zlib.lic '-o zlib,since=1996,author="Julian R Seward"' bzlib.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/bzlib.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/bzlib.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/bzlib.h generated
done install virtual
make test
done test dontcare virtual

View file

@ -1,2 +0,0 @@
The ast distribution has split the -lbz src from the command.
Please see $INSTALLROOT/src/cmd/bzip for license, copyright, and docs.

View file

@ -1,9 +0,0 @@
10-11-08 bzlib.[ch]: change bzReadGetUnused 3rd arg to void* for strict aliasing
09-04-15 bzlib.c: add bzfopen()
03-05-13 sfdcbzip.c: add SF_DBUFFER exception, SF_SHARE before sfreserve()
02-02-14 blocksort.c: drop -O for msvc
02-01-24 bzhdr.h: rename from bzlib_private.h for 14 char fs
01-01-01 bzlib.h: add _PACKAGE_ast checks
99-09-11 sfdcbzip: return >0 if discipline pushed
99-07-17 sfdcbzip: don't free disc on SF_CLOSE
99-03-17 split library from command, sfdcbzip.[ch]

View file

@ -1,710 +0,0 @@
#pragma prototyped
/*-------------------------------------------------------------*/
/*--- Block sorting machinery ---*/
/*--- blocksort.c ---*/
/*-------------------------------------------------------------*/
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
Copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0c of 18 October 1998
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
#include "bzhdr.h"
/*---------------------------------------------*/
/*--
Compare two strings in block. We assume (see
discussion above) that i1 and i2 have a max
offset of 10 on entry, and that the first
bytes of both block and quadrant have been
copied into the "overshoot area", ie
into the subscript range
[nblock .. nblock+NUM_OVERSHOOT_BYTES-1].
--*/
static __inline__ Bool fullGtU ( UChar* block,
UInt16* quadrant,
UInt32 nblock,
Int32* workDone,
Int32 i1,
Int32 i2
)
{
Int32 k;
UChar c1, c2;
UInt16 s1, s2;
AssertD ( i1 != i2, "fullGtU(1)" );
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
i1++; i2++;
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
i1++; i2++;
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
i1++; i2++;
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
i1++; i2++;
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
i1++; i2++;
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
i1++; i2++;
k = nblock;
do {
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
s1 = quadrant[i1];
s2 = quadrant[i2];
if (s1 != s2) return (s1 > s2);
i1++; i2++;
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
s1 = quadrant[i1];
s2 = quadrant[i2];
if (s1 != s2) return (s1 > s2);
i1++; i2++;
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
s1 = quadrant[i1];
s2 = quadrant[i2];
if (s1 != s2) return (s1 > s2);
i1++; i2++;
c1 = block[i1];
c2 = block[i2];
if (c1 != c2) return (c1 > c2);
s1 = quadrant[i1];
s2 = quadrant[i2];
if (s1 != s2) return (s1 > s2);
i1++; i2++;
if (i1 >= nblock) i1 -= nblock;
if (i2 >= nblock) i2 -= nblock;
k -= 4;
(*workDone)++;
}
while (k >= 0);
return False;
}
/*---------------------------------------------*/
/*--
Knuth's increments seem to work better
than Incerpi-Sedgewick here. Possibly
because the number of elems to sort is
usually small, typically <= 20.
--*/
static Int32 incs[14] = { 1, 4, 13, 40, 121, 364, 1093, 3280,
9841, 29524, 88573, 265720,
797161, 2391484 };
static void simpleSort ( EState* s, Int32 lo, Int32 hi, Int32 d )
{
Int32 i, j, h, bigN, hp;
Int32 v;
UChar* block = s->block;
UInt32* zptr = s->zptr;
UInt16* quadrant = s->quadrant;
Int32* workDone = &(s->workDone);
Int32 nblock = s->nblock;
Int32 workLimit = s->workLimit;
Bool firstAttempt = s->firstAttempt;
bigN = hi - lo + 1;
if (bigN < 2) return;
hp = 0;
while (incs[hp] < bigN) hp++;
hp--;
for (; hp >= 0; hp--) {
h = incs[hp];
i = lo + h;
while (True) {
/*-- copy 1 --*/
if (i > hi) break;
v = zptr[i];
j = i;
while ( fullGtU ( block, quadrant, nblock, workDone,
zptr[j-h]+d, v+d ) ) {
zptr[j] = zptr[j-h];
j = j - h;
if (j <= (lo + h - 1)) break;
}
zptr[j] = v;
i++;
/*-- copy 2 --*/
if (i > hi) break;
v = zptr[i];
j = i;
while ( fullGtU ( block, quadrant, nblock, workDone,
zptr[j-h]+d, v+d ) ) {
zptr[j] = zptr[j-h];
j = j - h;
if (j <= (lo + h - 1)) break;
}
zptr[j] = v;
i++;
/*-- copy 3 --*/
if (i > hi) break;
v = zptr[i];
j = i;
while ( fullGtU ( block, quadrant, nblock, workDone,
zptr[j-h]+d, v+d ) ) {
zptr[j] = zptr[j-h];
j = j - h;
if (j <= (lo + h - 1)) break;
}
zptr[j] = v;
i++;
if (*workDone > workLimit && firstAttempt) return;
}
}
}
/*---------------------------------------------*/
/*--
The following is an implementation of
an elegant 3-way quicksort for strings,
described in a paper "Fast Algorithms for
Sorting and Searching Strings", by Robert
Sedgewick and Jon L. Bentley.
--*/
#define swap(lv1, lv2) \
{ Int32 tmp = lv1; lv1 = lv2; lv2 = tmp; }
static void vswap ( UInt32* zptr, Int32 p1, Int32 p2, Int32 n )
{
while (n > 0) {
swap(zptr[p1], zptr[p2]);
p1++; p2++; n--;
}
}
static UChar med3 ( UChar a, UChar b, UChar c )
{
UChar t;
if (a > b) { t = a; a = b; b = t; };
if (b > c) { t = b; b = c; c = t; };
if (a > b) b = a;
return b;
}
#define min(a,b) ((a) < (b)) ? (a) : (b)
typedef
struct { Int32 ll; Int32 hh; Int32 dd; }
StackElem;
#define push(lz,hz,dz) { stack[sp].ll = lz; \
stack[sp].hh = hz; \
stack[sp].dd = dz; \
sp++; }
#define pop(lz,hz,dz) { sp--; \
lz = stack[sp].ll; \
hz = stack[sp].hh; \
dz = stack[sp].dd; }
#define SMALL_THRESH 20
#define DEPTH_THRESH 10
/*--
If you are ever unlucky/improbable enough
to get a stack overflow whilst sorting,
increase the following constant and try
again. In practice I have never seen the
stack go above 27 elems, so the following
limit seems very generous.
--*/
#define QSORT_STACK_SIZE 1000
static void qSort3 ( EState* s, Int32 loSt, Int32 hiSt, Int32 dSt )
{
Int32 unLo, unHi, ltLo, gtHi, med, n, m;
Int32 sp, lo, hi, d;
StackElem stack[QSORT_STACK_SIZE];
UChar* block = s->block;
UInt32* zptr = s->zptr;
Int32* workDone = &(s->workDone);
Int32 workLimit = s->workLimit;
Bool firstAttempt = s->firstAttempt;
sp = 0;
push ( loSt, hiSt, dSt );
while (sp > 0) {
AssertH ( sp < QSORT_STACK_SIZE, 1001 );
pop ( lo, hi, d );
if (hi - lo < SMALL_THRESH || d > DEPTH_THRESH) {
simpleSort ( s, lo, hi, d );
if (*workDone > workLimit && firstAttempt) return;
continue;
}
med = med3 ( block[zptr[ lo ]+d],
block[zptr[ hi ]+d],
block[zptr[ (lo+hi)>>1 ]+d] );
unLo = ltLo = lo;
unHi = gtHi = hi;
while (True) {
while (True) {
if (unLo > unHi) break;
n = ((Int32)block[zptr[unLo]+d]) - med;
if (n == 0) { swap(zptr[unLo], zptr[ltLo]); ltLo++; unLo++; continue; };
if (n > 0) break;
unLo++;
}
while (True) {
if (unLo > unHi) break;
n = ((Int32)block[zptr[unHi]+d]) - med;
if (n == 0) { swap(zptr[unHi], zptr[gtHi]); gtHi--; unHi--; continue; };
if (n < 0) break;
unHi--;
}
if (unLo > unHi) break;
swap(zptr[unLo], zptr[unHi]); unLo++; unHi--;
}
AssertD ( unHi == unLo-1, "bad termination in qSort3" );
if (gtHi < ltLo) {
push(lo, hi, d+1 );
continue;
}
n = min(ltLo-lo, unLo-ltLo); vswap(zptr, lo, unLo-n, n);
m = min(hi-gtHi, gtHi-unHi); vswap(zptr, unLo, hi-m+1, m);
n = lo + unLo - ltLo - 1;
m = hi - (gtHi - unHi) + 1;
push ( lo, n, d );
push ( n+1, m-1, d+1 );
push ( m, hi, d );
}
}
/*---------------------------------------------*/
#define BIGFREQ(b) (ftab[((b)+1) << 8] - ftab[(b) << 8])
#define SETMASK (1 << 21)
#define CLEARMASK (~(SETMASK))
static void sortMain ( EState* s )
{
Int32 i, j, k, ss, sb;
Int32 runningOrder[256];
Int32 copy[256];
Bool bigDone[256];
UChar c1, c2;
Int32 numQSorted;
UChar* block = s->block;
UInt32* zptr = s->zptr;
UInt16* quadrant = s->quadrant;
Int32* ftab = s->ftab;
Int32* workDone = &(s->workDone);
Int32 nblock = s->nblock;
Int32 workLimit = s->workLimit;
Bool firstAttempt = s->firstAttempt;
/*--
In the various block-sized structures, live data runs
from 0 to last+NUM_OVERSHOOT_BYTES inclusive. First,
set up the overshoot area for block.
--*/
if (s->verbosity >= 4)
VPrintf0( " sort initialise ...\n" );
for (i = 0; i < BZ_NUM_OVERSHOOT_BYTES; i++)
block[nblock+i] = block[i % nblock];
for (i = 0; i < nblock+BZ_NUM_OVERSHOOT_BYTES; i++)
quadrant[i] = 0;
if (nblock <= 4000) {
/*--
Use simpleSort(), since the full sorting mechanism
has quite a large constant overhead.
--*/
if (s->verbosity >= 4) VPrintf0( " simpleSort ...\n" );
for (i = 0; i < nblock; i++) zptr[i] = i;
firstAttempt = False;
*workDone = workLimit = 0;
simpleSort ( s, 0, nblock-1, 0 );
if (s->verbosity >= 4) VPrintf0( " simpleSort done.\n" );
} else {
numQSorted = 0;
for (i = 0; i <= 255; i++) bigDone[i] = False;
if (s->verbosity >= 4) VPrintf0( " bucket sorting ...\n" );
for (i = 0; i <= 65536; i++) ftab[i] = 0;
c1 = block[nblock-1];
for (i = 0; i < nblock; i++) {
c2 = block[i];
ftab[(c1 << 8) + c2]++;
c1 = c2;
}
for (i = 1; i <= 65536; i++) ftab[i] += ftab[i-1];
c1 = block[0];
for (i = 0; i < nblock-1; i++) {
c2 = block[i+1];
j = (c1 << 8) + c2;
c1 = c2;
ftab[j]--;
zptr[ftab[j]] = i;
}
j = (block[nblock-1] << 8) + block[0];
ftab[j]--;
zptr[ftab[j]] = nblock-1;
/*--
Now ftab contains the first loc of every small bucket.
Calculate the running order, from smallest to largest
big bucket.
--*/
for (i = 0; i <= 255; i++) runningOrder[i] = i;
{
Int32 vv;
Int32 h = 1;
do h = 3 * h + 1; while (h <= 256);
do {
h = h / 3;
for (i = h; i <= 255; i++) {
vv = runningOrder[i];
j = i;
while ( BIGFREQ(runningOrder[j-h]) > BIGFREQ(vv) ) {
runningOrder[j] = runningOrder[j-h];
j = j - h;
if (j <= (h - 1)) goto zero;
}
zero:
runningOrder[j] = vv;
}
} while (h != 1);
}
/*--
The main sorting loop.
--*/
for (i = 0; i <= 255; i++) {
/*--
Process big buckets, starting with the least full.
Basically this is a 4-step process in which we call
qSort3 to sort the small buckets [ss, j], but
also make a big effort to avoid the calls if we can.
--*/
ss = runningOrder[i];
/*--
Step 1:
Complete the big bucket [ss] by quicksorting
any unsorted small buckets [ss, j], for j != ss.
Hopefully previous pointer-scanning phases have already
completed many of the small buckets [ss, j], so
we don't have to sort them at all.
--*/
for (j = 0; j <= 255; j++) {
if (j != ss) {
sb = (ss << 8) + j;
if ( ! (ftab[sb] & SETMASK) ) {
Int32 lo = ftab[sb] & CLEARMASK;
Int32 hi = (ftab[sb+1] & CLEARMASK) - 1;
if (hi > lo) {
if (s->verbosity >= 4)
VPrintf4( " qsort [0x%x, 0x%x] done %d this %d\n",
ss, j, numQSorted, hi - lo + 1 );
qSort3 ( s, lo, hi, 2 );
numQSorted += ( hi - lo + 1 );
if (*workDone > workLimit && firstAttempt) return;
}
}
ftab[sb] |= SETMASK;
}
}
/*--
Step 2:
Deal specially with case [ss, ss]. This establishes the
sorted order for [ss, ss] without any comparisons.
A clever trick, cryptically described as steps Q6b and Q6c
in SRC-124 (aka BW94). This makes it entirely practical to
not use a preliminary run-length coder, but unfortunately
we are now stuck with the .bz2 file format.
--*/
{
Int32 put0, get0, put1, get1;
Int32 sbn = (ss << 8) + ss;
Int32 lo = ftab[sbn] & CLEARMASK;
Int32 hi = (ftab[sbn+1] & CLEARMASK) - 1;
UChar ssc = (UChar)ss;
put0 = lo;
get0 = ftab[ss << 8] & CLEARMASK;
put1 = hi;
get1 = (ftab[(ss+1) << 8] & CLEARMASK) - 1;
while (get0 < put0) {
j = zptr[get0]-1; if (j < 0) j += nblock;
c1 = block[j];
if (c1 == ssc) { zptr[put0] = j; put0++; };
get0++;
}
while (get1 > put1) {
j = zptr[get1]-1; if (j < 0) j += nblock;
c1 = block[j];
if (c1 == ssc) { zptr[put1] = j; put1--; };
get1--;
}
ftab[sbn] |= SETMASK;
}
/*--
Step 3:
The [ss] big bucket is now done. Record this fact,
and update the quadrant descriptors. Remember to
update quadrants in the overshoot area too, if
necessary. The "if (i < 255)" test merely skips
this updating for the last bucket processed, since
updating for the last bucket is pointless.
The quadrant array provides a way to incrementally
cache sort orderings, as they appear, so as to
make subsequent comparisons in fullGtU() complete
faster. For repetitive blocks this makes a big
difference (but not big enough to be able to avoid
randomisation for very repetitive data.)
The precise meaning is: at all times:
for 0 <= i < nblock and 0 <= j <= nblock
if block[i] != block[j],
then the relative values of quadrant[i] and
quadrant[j] are meaningless.
else {
if quadrant[i] < quadrant[j]
then the string starting at i lexicographically
precedes the string starting at j
else if quadrant[i] > quadrant[j]
then the string starting at j lexicographically
precedes the string starting at i
else
the relative ordering of the strings starting
at i and j has not yet been determined.
}
--*/
bigDone[ss] = True;
if (i < 255) {
Int32 bbStart = ftab[ss << 8] & CLEARMASK;
Int32 bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
Int32 shifts = 0;
while ((bbSize >> shifts) > 65534) shifts++;
for (j = 0; j < bbSize; j++) {
Int32 a2update = zptr[bbStart + j];
UInt16 qVal = (UInt16)(j >> shifts);
quadrant[a2update] = qVal;
if (a2update < BZ_NUM_OVERSHOOT_BYTES)
quadrant[a2update + nblock] = qVal;
}
AssertH ( ( ((bbSize-1) >> shifts) <= 65535 ), 1002 );
}
/*--
Step 4:
Now scan this big bucket [ss] so as to synthesise the
sorted order for small buckets [t, ss] for all t != ss.
This will avoid doing Real Work in subsequent Step 1's.
--*/
for (j = 0; j <= 255; j++)
copy[j] = ftab[(j << 8) + ss] & CLEARMASK;
for (j = ftab[ss << 8] & CLEARMASK;
j < (ftab[(ss+1) << 8] & CLEARMASK);
j++) {
k = zptr[j]-1; if (k < 0) k += nblock;
c1 = block[k];
if ( ! bigDone[c1] ) {
zptr[copy[c1]] = k;
copy[c1] ++;
}
}
for (j = 0; j <= 255; j++) ftab[(j << 8) + ss] |= SETMASK;
}
if (s->verbosity >= 4)
VPrintf3( " %d pointers, %d sorted, %d scanned\n",
nblock, numQSorted, nblock - numQSorted );
}
}
/*---------------------------------------------*/
static void randomiseBlock ( EState* s )
{
Int32 i;
BZ_RAND_INIT_MASK;
for (i = 0; i < 256; i++) s->inUse[i] = False;
for (i = 0; i < s->nblock; i++) {
BZ_RAND_UPD_MASK;
s->block[i] ^= BZ_RAND_MASK;
s->inUse[s->block[i]] = True;
}
}
/*---------------------------------------------*/
void blockSort ( EState* s )
{
Int32 i;
s->workLimit = s->workFactor * (s->nblock - 1);
s->workDone = 0;
s->blockRandomised = False;
s->firstAttempt = True;
sortMain ( s );
if (s->verbosity >= 3)
VPrintf3( " %d work, %d block, ratio %5.2f\n",
s->workDone, s->nblock-1,
(float)(s->workDone) / (float)(s->nblock-1) );
if (s->workDone > s->workLimit && s->firstAttempt) {
if (s->verbosity >= 2)
VPrintf0( " sorting aborted; randomising block\n" );
randomiseBlock ( s );
s->workLimit = s->workDone = 0;
s->blockRandomised = True;
s->firstAttempt = False;
sortMain ( s );
if (s->verbosity >= 3)
VPrintf3( " %d work, %d block, ratio %f\n",
s->workDone, s->nblock-1,
(float)(s->workDone) / (float)(s->nblock-1) );
}
s->origPtr = -1;
for (i = 0; i < s->nblock; i++)
if (s->zptr[i] == 0)
{ s->origPtr = i; break; };
AssertH( s->origPtr != -1, 1003 );
}
/*-------------------------------------------------------------*/
/*--- end blocksort.c ---*/
/*-------------------------------------------------------------*/

View file

@ -1,528 +0,0 @@
#pragma prototyped
/*-------------------------------------------------------------*/
/*--- Private header file for the library. ---*/
/*--- bzhdr.h ---*/
/*-------------------------------------------------------------*/
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
Copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0c of 18 October 1998
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
#ifndef _BZLIB_PRIVATE_H
#define _BZLIB_PRIVATE_H
#if _PACKAGE_ast
#include <ast_std.h>
#else
#include <stdlib.h>
#endif
#ifndef BZ_NO_STDIO
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#endif
#include "bzlib.h"
/*-- General stuff. --*/
#define BZ_VERSION "0.9.0c"
typedef char Char;
typedef unsigned char Bool;
typedef unsigned char UChar;
typedef int Int32;
typedef unsigned int UInt32;
typedef short Int16;
typedef unsigned short UInt16;
#define True ((Bool)1)
#define False ((Bool)0)
#ifndef __GNUC__
#define __inline__ /* */
#endif
#ifndef BZ_NO_STDIO
extern void bz__AssertH__fail ( int errcode );
#define AssertH(cond,errcode) \
{ if (!(cond)) bz__AssertH__fail ( errcode ); }
#if BZ_DEBUG
#define AssertD(cond,msg) \
{ if (!(cond)) { \
fprintf ( stderr, \
"\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\
exit(1); \
}}
#else
#define AssertD(cond,msg) /* */
#endif
#define VPrintf0(zf) \
fprintf(stderr,zf)
#define VPrintf1(zf,za1) \
fprintf(stderr,zf,za1)
#define VPrintf2(zf,za1,za2) \
fprintf(stderr,zf,za1,za2)
#define VPrintf3(zf,za1,za2,za3) \
fprintf(stderr,zf,za1,za2,za3)
#define VPrintf4(zf,za1,za2,za3,za4) \
fprintf(stderr,zf,za1,za2,za3,za4)
#define VPrintf5(zf,za1,za2,za3,za4,za5) \
fprintf(stderr,zf,za1,za2,za3,za4,za5)
#else
extern void bz_internal_error ( int errcode );
#define AssertH(cond,errcode) \
{ if (!(cond)) bz_internal_error ( errcode ); }
#define AssertD(cond,msg) /* */
#define VPrintf0(zf) /* */
#define VPrintf1(zf,za1) /* */
#define VPrintf2(zf,za1,za2) /* */
#define VPrintf3(zf,za1,za2,za3) /* */
#define VPrintf4(zf,za1,za2,za3,za4) /* */
#define VPrintf5(zf,za1,za2,za3,za4,za5) /* */
#endif
#define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1)
#define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp))
/*-- Constants for the back end. --*/
#define BZ_MAX_ALPHA_SIZE 258
#define BZ_MAX_CODE_LEN 23
#define BZ_RUNA 0
#define BZ_RUNB 1
#define BZ_N_GROUPS 6
#define BZ_G_SIZE 50
#define BZ_N_ITERS 4
#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
/*-- Stuff for randomising repetitive blocks. --*/
extern Int32 rNums[512];
#define BZ_RAND_DECLS \
Int32 rNToGo; \
Int32 rTPos \
#define BZ_RAND_INIT_MASK \
s->rNToGo = 0; \
s->rTPos = 0 \
#define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0)
#define BZ_RAND_UPD_MASK \
if (s->rNToGo == 0) { \
s->rNToGo = rNums[s->rTPos]; \
s->rTPos++; \
if (s->rTPos == 512) s->rTPos = 0; \
} \
s->rNToGo--;
/*-- Stuff for doing CRCs. --*/
extern UInt32 crc32Table[256];
#define BZ_INITIALISE_CRC(crcVar) \
{ \
crcVar = 0xffffffffL; \
}
#define BZ_FINALISE_CRC(crcVar) \
{ \
crcVar = ~(crcVar); \
}
#define BZ_UPDATE_CRC(crcVar,cha) \
{ \
crcVar = (crcVar << 8) ^ \
crc32Table[(crcVar >> 24) ^ \
((UChar)cha)]; \
}
/*-- States and modes for compression. --*/
#define BZ_M_IDLE 1
#define BZ_M_RUNNING 2
#define BZ_M_FLUSHING 3
#define BZ_M_FINISHING 4
#define BZ_S_OUTPUT 1
#define BZ_S_INPUT 2
#define BZ_NUM_OVERSHOOT_BYTES 20
/*-- Structure holding all the compression-side stuff. --*/
typedef
struct {
/* pointer back to the struct bz_stream */
bz_stream* strm;
/* mode this stream is in, and whether inputting */
/* or outputting data */
Int32 mode;
Int32 state;
/* remembers avail_in when flush/finish requested */
UInt32 avail_in_expect;
/* for doing the block sorting */
UChar* block;
UInt16* quadrant;
UInt32* zptr;
UInt16* szptr;
Int32* ftab;
Int32 workDone;
Int32 workLimit;
Int32 workFactor;
Bool firstAttempt;
Bool blockRandomised;
Int32 origPtr;
/* run-length-encoding of the input */
UInt32 state_in_ch;
Int32 state_in_len;
BZ_RAND_DECLS;
/* input and output limits and current posns */
Int32 nblock;
Int32 nblockMAX;
Int32 numZ;
Int32 state_out_pos;
/* map of bytes used in block */
Int32 nInUse;
Bool inUse[256];
UChar unseqToSeq[256];
/* the buffer for bit stream creation */
UInt32 bsBuff;
Int32 bsLive;
/* block and combined CRCs */
UInt32 blockCRC;
UInt32 combinedCRC;
/* misc administratium */
Int32 verbosity;
Int32 blockNo;
Int32 nBlocksRandomised;
Int32 blockSize100k;
/* stuff for coding the MTF values */
Int32 nMTF;
Int32 mtfFreq [BZ_MAX_ALPHA_SIZE];
UChar selector [BZ_MAX_SELECTORS];
UChar selectorMtf[BZ_MAX_SELECTORS];
UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
Int32 rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
}
EState;
/*-- externs for compression. --*/
extern void
blockSort ( EState* );
extern void
compressBlock ( EState*, Bool );
extern void
bsInitWrite ( EState* );
extern void
hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 );
extern void
hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 );
/*-- states for decompression. --*/
#define BZ_X_IDLE 1
#define BZ_X_OUTPUT 2
#define BZ_X_MAGIC_1 10
#define BZ_X_MAGIC_2 11
#define BZ_X_MAGIC_3 12
#define BZ_X_MAGIC_4 13
#define BZ_X_BLKHDR_1 14
#define BZ_X_BLKHDR_2 15
#define BZ_X_BLKHDR_3 16
#define BZ_X_BLKHDR_4 17
#define BZ_X_BLKHDR_5 18
#define BZ_X_BLKHDR_6 19
#define BZ_X_BCRC_1 20
#define BZ_X_BCRC_2 21
#define BZ_X_BCRC_3 22
#define BZ_X_BCRC_4 23
#define BZ_X_RANDBIT 24
#define BZ_X_ORIGPTR_1 25
#define BZ_X_ORIGPTR_2 26
#define BZ_X_ORIGPTR_3 27
#define BZ_X_MAPPING_1 28
#define BZ_X_MAPPING_2 29
#define BZ_X_SELECTOR_1 30
#define BZ_X_SELECTOR_2 31
#define BZ_X_SELECTOR_3 32
#define BZ_X_CODING_1 33
#define BZ_X_CODING_2 34
#define BZ_X_CODING_3 35
#define BZ_X_MTF_1 36
#define BZ_X_MTF_2 37
#define BZ_X_MTF_3 38
#define BZ_X_MTF_4 39
#define BZ_X_MTF_5 40
#define BZ_X_MTF_6 41
#define BZ_X_ENDHDR_2 42
#define BZ_X_ENDHDR_3 43
#define BZ_X_ENDHDR_4 44
#define BZ_X_ENDHDR_5 45
#define BZ_X_ENDHDR_6 46
#define BZ_X_CCRC_1 47
#define BZ_X_CCRC_2 48
#define BZ_X_CCRC_3 49
#define BZ_X_CCRC_4 50
/*-- Constants for the fast MTF decoder. --*/
#define MTFA_SIZE 4096
#define MTFL_SIZE 16
/*-- Structure holding all the decompression-side stuff. --*/
typedef
struct {
/* pointer back to the struct bz_stream */
bz_stream* strm;
/* state indicator for this stream */
Int32 state;
/* for doing the final run-length decoding */
UChar state_out_ch;
Int32 state_out_len;
Bool blockRandomised;
BZ_RAND_DECLS;
/* the buffer for bit stream reading */
UInt32 bsBuff;
Int32 bsLive;
/* misc administratium */
Int32 blockSize100k;
Bool smallDecompress;
Int32 currBlockNo;
Int32 verbosity;
/* for undoing the Burrows-Wheeler transform */
Int32 origPtr;
UInt32 tPos;
Int32 k0;
Int32 unzftab[256];
Int32 nblock_used;
Int32 cftab[257];
Int32 cftabCopy[257];
/* for undoing the Burrows-Wheeler transform (FAST) */
UInt32 *tt;
/* for undoing the Burrows-Wheeler transform (SMALL) */
UInt16 *ll16;
UChar *ll4;
/* stored and calculated CRCs */
UInt32 storedBlockCRC;
UInt32 storedCombinedCRC;
UInt32 calculatedBlockCRC;
UInt32 calculatedCombinedCRC;
/* map of bytes used in block */
Int32 nInUse;
Bool inUse[256];
Bool inUse16[16];
UChar seqToUnseq[256];
/* for decoding the MTF values */
UChar mtfa [MTFA_SIZE];
Int32 mtfbase[256 / MTFL_SIZE];
UChar selector [BZ_MAX_SELECTORS];
UChar selectorMtf[BZ_MAX_SELECTORS];
UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
Int32 minLens[BZ_N_GROUPS];
/* save area for scalars in the main decompress code */
Int32 save_i;
Int32 save_j;
Int32 save_t;
Int32 save_alphaSize;
Int32 save_nGroups;
Int32 save_nSelectors;
Int32 save_EOB;
Int32 save_groupNo;
Int32 save_groupPos;
Int32 save_nextSym;
Int32 save_nblockMAX;
Int32 save_nblock;
Int32 save_es;
Int32 save_N;
Int32 save_curr;
Int32 save_zt;
Int32 save_zn;
Int32 save_zvec;
Int32 save_zj;
Int32 save_gSel;
Int32 save_gMinlen;
Int32* save_gLimit;
Int32* save_gBase;
Int32* save_gPerm;
}
DState;
/*-- Macros for decompression. --*/
#define BZ_GET_FAST(cccc) \
s->tPos = s->tt[s->tPos]; \
cccc = (UChar)(s->tPos & 0xff); \
s->tPos >>= 8;
#define BZ_GET_FAST_C(cccc) \
c_tPos = c_tt[c_tPos]; \
cccc = (UChar)(c_tPos & 0xff); \
c_tPos >>= 8;
#define SET_LL4(i,n) \
{ if (((i) & 0x1) == 0) \
s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \
s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \
}
#define GET_LL4(i) \
(((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4) & 0xF)
#define SET_LL(i,n) \
{ s->ll16[i] = (UInt16)(n & 0x0000ffff); \
SET_LL4(i, n >> 16); \
}
#define GET_LL(i) \
(((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
#define BZ_GET_SMALL(cccc) \
cccc = indexIntoF ( s->tPos, s->cftab ); \
s->tPos = GET_LL(s->tPos);
/*-- externs for decompression. --*/
extern Int32
indexIntoF ( Int32, Int32* );
extern Int32
decompress ( DState* );
extern void
hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*,
Int32, Int32, Int32 );
#endif
/*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/
#ifdef BZ_NO_STDIO
#ifndef NULL
#define NULL 0
#endif
#endif
/*-------------------------------------------------------------*/
/*--- end bzhdr.h ---*/
/*-------------------------------------------------------------*/

File diff suppressed because it is too large Load diff

View file

@ -1,353 +0,0 @@
#pragma prototyped
/*-------------------------------------------------------------*/
/*--- Public header file for the library. ---*/
/*--- bzlib.h ---*/
/*-------------------------------------------------------------*/
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
Copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0c of 18 October 1998
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
#ifndef _BZLIB_H
#define _BZLIB_H
#define BZ_RUN 0
#define BZ_FLUSH 1
#define BZ_FINISH 2
#define BZ_OK 0
#define BZ_RUN_OK 1
#define BZ_FLUSH_OK 2
#define BZ_FINISH_OK 3
#define BZ_STREAM_END 4
#define BZ_SEQUENCE_ERROR (-1)
#define BZ_PARAM_ERROR (-2)
#define BZ_MEM_ERROR (-3)
#define BZ_DATA_ERROR (-4)
#define BZ_DATA_ERROR_MAGIC (-5)
#define BZ_IO_ERROR (-6)
#define BZ_UNEXPECTED_EOF (-7)
#define BZ_OUTBUFF_FULL (-8)
typedef
struct {
char *next_in;
unsigned int avail_in;
unsigned int total_in;
char *next_out;
unsigned int avail_out;
unsigned int total_out;
void *state;
void *(*bzalloc)(void *,int,int);
void (*bzfree)(void *,void *);
void *opaque;
}
bz_stream;
#if _PACKAGE_ast
#include <ast_std.h>
#else
#if !defined(_WINIX) && (_UWIN || __CYGWIN__ || __EMX__)
#define _WINIX 1
#endif
#endif
/*---------------------------------------------*/
/*--
Generic 32-bit Unix.
Also works on 64-bit Unix boxes.
--*/
#if !_WIN32 || _WINIX
#define BZ_UNIX 1
#endif
/*--
Win32, as seen by Jacob Navia's excellent
port of (Chris Fraser & David Hanson)'s excellent
lcc compiler.
--*/
#if _WIN32 && !_WINIX
#define BZ_LCCWIN32 1
#define BZ_UNIX 0
#else
#define BZ_LCCWIN32 0
#endif
#include <stdio.h>
#if _BLD_bz
#if defined(__EXPORT__)
# define BZ_API(func) func
# define BZ_EXTERN __EXPORT__
#else
# define BZ_API(func) func
# define BZ_EXTERN extern
#endif
#else
#if _WIN32 && !_WINIX
# include <windows.h>
# ifdef small
/* windows.h define small to char */
# undef small
# endif
# ifdef BZ_EXPORT
# define BZ_API(func) WINAPI func
# define BZ_EXTERN extern
# else
/* import windows dll dynamically */
# define BZ_API(func) (WINAPI * func)
# define BZ_EXTERN
# endif
#else
# define BZ_API(func) func
# define BZ_EXTERN extern
#endif
#endif
/*-- Core (low-level) library functions --*/
BZ_EXTERN int BZ_API(bzCompressInit) (
bz_stream* strm,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN int BZ_API(bzCompress) (
bz_stream* strm,
int action
);
BZ_EXTERN int BZ_API(bzCompressEnd) (
bz_stream* strm
);
BZ_EXTERN int BZ_API(bzDecompressInit) (
bz_stream *strm,
int verbosity,
int small
);
BZ_EXTERN int BZ_API(bzDecompress) (
bz_stream* strm
);
BZ_EXTERN int BZ_API(bzDecompressEnd) (
bz_stream *strm
);
/*-- High(er) level library functions --*/
#ifndef BZ_NO_STDIO
#define BZ_MAX_UNUSED 5000
typedef void BZFILE;
typedef BZFILE Bz_t;
BZ_EXTERN BZFILE* BZ_API(bzReadOpen) (
int* bzerror,
FILE* f,
int verbosity,
int small,
void* unused,
int nUnused
);
BZ_EXTERN void BZ_API(bzReadClose) (
int* bzerror,
BZFILE* b
);
BZ_EXTERN void BZ_API(bzReadGetUnused) (
int* bzerror,
BZFILE* b,
void* vUnused,
int* nUnused
);
BZ_EXTERN int BZ_API(bzRead) (
int* bzerror,
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN BZFILE* BZ_API(bzWriteOpen) (
int* bzerror,
FILE* f,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN void BZ_API(bzWrite) (
int* bzerror,
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN void BZ_API(bzWriteClose) (
int* bzerror,
BZFILE* b,
int abandon,
unsigned int* nbytes_in,
unsigned int* nbytes_out
);
#endif
/*-- Utility functions --*/
BZ_EXTERN int BZ_API(bzBuffToBuffCompress) (
char* dest,
unsigned int* destLen,
char* source,
unsigned int sourceLen,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN int BZ_API(bzBuffToBuffDecompress) (
char* dest,
unsigned int* destLen,
char* source,
unsigned int sourceLen,
int small,
int verbosity
);
/*--
Code contributed by Yoshioka Tsuneo
(QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
to support better zlib compatibility.
This code is not _officially_ part of libbzip2 (yet);
I haven't tested it, documented it, or considered the
threading-safeness of it.
If this code breaks, please contact both Yoshioka and me.
--*/
BZ_EXTERN const char * BZ_API(bzlibVersion) (
void
);
#ifndef BZ_NO_STDIO
BZ_EXTERN BZFILE * BZ_API(bzopen) (
const char *path,
const char *mode
);
BZ_EXTERN BZFILE * BZ_API(bzfopen) (
FILE *fp,
const char *mode
);
BZ_EXTERN BZFILE * BZ_API(bzdopen) (
int fd,
const char *mode
);
BZ_EXTERN BZFILE * BZ_API(bzbopen) (
int fd,
const char* mode,
const void* buf,
unsigned int len
);
BZ_EXTERN int BZ_API(bzread) (
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN int BZ_API(bzwrite) (
BZFILE* b,
const void* buf,
int len
);
BZ_EXTERN int BZ_API(bzflush) (
BZFILE* b
);
BZ_EXTERN int BZ_API(bzclose) (
BZFILE* b
);
BZ_EXTERN const char * BZ_API(bzerror) (
BZFILE *b,
int *errnum
);
#endif
#endif
/*-------------------------------------------------------------*/
/*--- end bzlib.h ---*/
/*-------------------------------------------------------------*/

View file

@ -1,589 +0,0 @@
#pragma prototyped
/*-------------------------------------------------------------*/
/*--- Compression machinery (not incl block sorting) ---*/
/*--- compress.c ---*/
/*-------------------------------------------------------------*/
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
Copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0 of 28 June 1998
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
/*--
CHANGES
~~~~~~~
0.9.0 -- original version.
0.9.0a/b -- no changes in this file.
0.9.0c
* changed setting of nGroups in sendMTFValues() so as to
do a bit better on small files
--*/
#include "bzhdr.h"
/*---------------------------------------------------*/
/*--- Bit stream I/O ---*/
/*---------------------------------------------------*/
/*---------------------------------------------------*/
void bsInitWrite ( EState* s )
{
s->bsLive = 0;
s->bsBuff = 0;
}
/*---------------------------------------------------*/
static
void bsFinishWrite ( EState* s )
{
while (s->bsLive > 0) {
((UChar*)(s->quadrant))[s->numZ] = (UChar)(s->bsBuff >> 24);
s->numZ++;
s->bsBuff <<= 8;
s->bsLive -= 8;
}
}
/*---------------------------------------------------*/
#define bsNEEDW(nz) \
{ \
while (s->bsLive >= 8) { \
((UChar*)(s->quadrant))[s->numZ] \
= (UChar)(s->bsBuff >> 24); \
s->numZ++; \
s->bsBuff <<= 8; \
s->bsLive -= 8; \
} \
}
/*---------------------------------------------------*/
static
void bsW ( EState* s, Int32 n, UInt32 v )
{
bsNEEDW ( n );
s->bsBuff |= (v << (32 - s->bsLive - n));
s->bsLive += n;
}
/*---------------------------------------------------*/
static
void bsPutUInt32 ( EState* s, UInt32 u )
{
bsW ( s, 8, (u >> 24) & 0xffL );
bsW ( s, 8, (u >> 16) & 0xffL );
bsW ( s, 8, (u >> 8) & 0xffL );
bsW ( s, 8, u & 0xffL );
}
/*---------------------------------------------------*/
static
void bsPutUChar ( EState* s, UChar c )
{
bsW( s, 8, (UInt32)c );
}
/*---------------------------------------------------*/
/*--- The back end proper ---*/
/*---------------------------------------------------*/
/*---------------------------------------------------*/
static
void makeMaps_e ( EState* s )
{
Int32 i;
s->nInUse = 0;
for (i = 0; i < 256; i++)
if (s->inUse[i]) {
s->unseqToSeq[i] = s->nInUse;
s->nInUse++;
}
}
/*---------------------------------------------------*/
static
void generateMTFValues ( EState* s )
{
UChar yy[256];
Int32 i, j;
UChar tmp;
UChar tmp2;
Int32 zPend;
Int32 wr;
Int32 EOB;
makeMaps_e ( s );
EOB = s->nInUse+1;
for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0;
wr = 0;
zPend = 0;
for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i;
for (i = 0; i < s->nblock; i++) {
UChar ll_i;
AssertD ( wr <= i, "generateMTFValues(1)" );
j = s->zptr[i]-1; if (j < 0) j += s->nblock;
ll_i = s->unseqToSeq[s->block[j]];
AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" );
j = 0;
tmp = yy[j];
while ( ll_i != tmp ) {
j++;
tmp2 = tmp;
tmp = yy[j];
yy[j] = tmp2;
};
yy[0] = tmp;
if (j == 0) {
zPend++;
} else {
if (zPend > 0) {
zPend--;
while (True) {
switch (zPend % 2) {
case 0: s->szptr[wr] = BZ_RUNA; wr++; s->mtfFreq[BZ_RUNA]++; break;
case 1: s->szptr[wr] = BZ_RUNB; wr++; s->mtfFreq[BZ_RUNB]++; break;
};
if (zPend < 2) break;
zPend = (zPend - 2) / 2;
};
zPend = 0;
}
s->szptr[wr] = j+1; wr++; s->mtfFreq[j+1]++;
}
}
if (zPend > 0) {
zPend--;
while (True) {
switch (zPend % 2) {
case 0: s->szptr[wr] = BZ_RUNA; wr++; s->mtfFreq[BZ_RUNA]++; break;
case 1: s->szptr[wr] = BZ_RUNB; wr++; s->mtfFreq[BZ_RUNB]++; break;
};
if (zPend < 2) break;
zPend = (zPend - 2) / 2;
};
}
s->szptr[wr] = EOB; wr++; s->mtfFreq[EOB]++;
s->nMTF = wr;
}
/*---------------------------------------------------*/
#define BZ_LESSER_ICOST 0
#define BZ_GREATER_ICOST 15
static
void sendMTFValues ( EState* s )
{
Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
Int32 nSelectors, alphaSize, minLen, maxLen, selCtr;
Int32 nGroups, nBytes;
/*--
UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
is a global since the decoder also needs it.
Int32 code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
Int32 rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
are also globals only used in this proc.
Made global to keep stack frame size small.
--*/
UInt16 cost[BZ_N_GROUPS];
Int32 fave[BZ_N_GROUPS];
if (s->verbosity >= 3)
VPrintf3( " %d in block, %d after MTF & 1-2 coding, "
"%d+2 syms in use\n",
s->nblock, s->nMTF, s->nInUse );
alphaSize = s->nInUse+2;
for (t = 0; t < BZ_N_GROUPS; t++)
for (v = 0; v < alphaSize; v++)
s->len[t][v] = BZ_GREATER_ICOST;
/*--- Decide how many coding tables to use ---*/
AssertH ( s->nMTF > 0, 3001 );
if (s->nMTF < 200) nGroups = 2; else
if (s->nMTF < 600) nGroups = 3; else
if (s->nMTF < 1200) nGroups = 4; else
if (s->nMTF < 2400) nGroups = 5; else
nGroups = 6;
/*--- Generate an initial set of coding tables ---*/
{
Int32 nPart, remF, tFreq, aFreq;
nPart = nGroups;
remF = s->nMTF;
gs = 0;
while (nPart > 0) {
tFreq = remF / nPart;
ge = gs-1;
aFreq = 0;
while (aFreq < tFreq && ge < alphaSize-1) {
ge++;
aFreq += s->mtfFreq[ge];
}
if (ge > gs
&& nPart != nGroups && nPart != 1
&& ((nGroups-nPart) % 2 == 1)) {
aFreq -= s->mtfFreq[ge];
ge--;
}
if (s->verbosity >= 3)
VPrintf5( " initial group %d, [%d .. %d], "
"has %d syms (%4.1f%%)\n",
nPart, gs, ge, aFreq,
(100.0 * (float)aFreq) / (float)(s->nMTF) );
for (v = 0; v < alphaSize; v++)
if (v >= gs && v <= ge)
s->len[nPart-1][v] = BZ_LESSER_ICOST; else
s->len[nPart-1][v] = BZ_GREATER_ICOST;
nPart--;
gs = ge+1;
remF -= aFreq;
}
}
/*---
Iterate up to BZ_N_ITERS times to improve the tables.
---*/
for (iter = 0; iter < BZ_N_ITERS; iter++) {
for (t = 0; t < nGroups; t++) fave[t] = 0;
for (t = 0; t < nGroups; t++)
for (v = 0; v < alphaSize; v++)
s->rfreq[t][v] = 0;
nSelectors = 0;
totc = 0;
gs = 0;
while (True) {
/*--- Set group start & end marks. --*/
if (gs >= s->nMTF) break;
ge = gs + BZ_G_SIZE - 1;
if (ge >= s->nMTF) ge = s->nMTF-1;
/*--
Calculate the cost of this group as coded
by each of the coding tables.
--*/
for (t = 0; t < nGroups; t++) cost[t] = 0;
if (nGroups == 6) {
register UInt16 cost0, cost1, cost2, cost3, cost4, cost5;
cost0 = cost1 = cost2 = cost3 = cost4 = cost5 = 0;
for (i = gs; i <= ge; i++) {
UInt16 icv = s->szptr[i];
cost0 += s->len[0][icv];
cost1 += s->len[1][icv];
cost2 += s->len[2][icv];
cost3 += s->len[3][icv];
cost4 += s->len[4][icv];
cost5 += s->len[5][icv];
}
cost[0] = cost0; cost[1] = cost1; cost[2] = cost2;
cost[3] = cost3; cost[4] = cost4; cost[5] = cost5;
} else {
for (i = gs; i <= ge; i++) {
UInt16 icv = s->szptr[i];
for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv];
}
}
/*--
Find the coding table which is best for this group,
and record its identity in the selector table.
--*/
bc = 999999999; bt = -1;
for (t = 0; t < nGroups; t++)
if (cost[t] < bc) { bc = cost[t]; bt = t; };
totc += bc;
fave[bt]++;
s->selector[nSelectors] = bt;
nSelectors++;
/*--
Increment the symbol frequencies for the selected table.
--*/
for (i = gs; i <= ge; i++)
s->rfreq[bt][ s->szptr[i] ]++;
gs = ge+1;
}
if (s->verbosity >= 3) {
VPrintf2 ( " pass %d: size is %d, grp uses are ",
iter+1, totc/8 );
for (t = 0; t < nGroups; t++)
VPrintf1 ( "%d ", fave[t] );
VPrintf0 ( "\n" );
}
/*--
Recompute the tables based on the accumulated frequencies.
--*/
for (t = 0; t < nGroups; t++)
hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
alphaSize, 20 );
}
AssertH( nGroups < 8, 3002 );
AssertH( nSelectors < 32768 &&
nSelectors <= (2 + (900000 / BZ_G_SIZE)),
3003 );
/*--- Compute MTF values for the selectors. ---*/
{
UChar pos[BZ_N_GROUPS], ll_i, tmp2, tmp;
for (i = 0; i < nGroups; i++) pos[i] = i;
for (i = 0; i < nSelectors; i++) {
ll_i = s->selector[i];
j = 0;
tmp = pos[j];
while ( ll_i != tmp ) {
j++;
tmp2 = tmp;
tmp = pos[j];
pos[j] = tmp2;
};
pos[0] = tmp;
s->selectorMtf[i] = j;
}
};
/*--- Assign actual codes for the tables. --*/
for (t = 0; t < nGroups; t++) {
minLen = 32;
maxLen = 0;
for (i = 0; i < alphaSize; i++) {
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
if (s->len[t][i] < minLen) minLen = s->len[t][i];
}
AssertH ( !(maxLen > 20), 3004 );
AssertH ( !(minLen < 1), 3005 );
hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
minLen, maxLen, alphaSize );
}
/*--- Transmit the mapping table. ---*/
{
Bool inUse16[16];
for (i = 0; i < 16; i++) {
inUse16[i] = False;
for (j = 0; j < 16; j++)
if (s->inUse[i * 16 + j]) inUse16[i] = True;
}
nBytes = s->numZ;
for (i = 0; i < 16; i++)
if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
for (i = 0; i < 16; i++)
if (inUse16[i])
for (j = 0; j < 16; j++) {
if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0);
}
if (s->verbosity >= 3)
VPrintf1( " bytes: mapping %d, ", s->numZ-nBytes );
}
/*--- Now the selectors. ---*/
nBytes = s->numZ;
bsW ( s, 3, nGroups );
bsW ( s, 15, nSelectors );
for (i = 0; i < nSelectors; i++) {
for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1);
bsW(s,1,0);
}
if (s->verbosity >= 3)
VPrintf1( "selectors %d, ", s->numZ-nBytes );
/*--- Now the coding tables. ---*/
nBytes = s->numZ;
for (t = 0; t < nGroups; t++) {
Int32 curr = s->len[t][0];
bsW ( s, 5, curr );
for (i = 0; i < alphaSize; i++) {
while (curr < s->len[t][i]) { bsW(s,2,2); curr++; /* 10 */ };
while (curr > s->len[t][i]) { bsW(s,2,3); curr--; /* 11 */ };
bsW ( s, 1, 0 );
}
}
if (s->verbosity >= 3)
VPrintf1 ( "code lengths %d, ", s->numZ-nBytes );
/*--- And finally, the block data proper ---*/
nBytes = s->numZ;
selCtr = 0;
gs = 0;
while (True) {
if (gs >= s->nMTF) break;
ge = gs + BZ_G_SIZE - 1;
if (ge >= s->nMTF) ge = s->nMTF-1;
for (i = gs; i <= ge; i++) {
AssertH ( s->selector[selCtr] < nGroups, 3006 );
bsW ( s,
s->len [s->selector[selCtr]] [s->szptr[i]],
s->code [s->selector[selCtr]] [s->szptr[i]] );
}
gs = ge+1;
selCtr++;
}
AssertH( selCtr == nSelectors, 3007 );
if (s->verbosity >= 3)
VPrintf1( "codes %d\n", s->numZ-nBytes );
}
/*---------------------------------------------------*/
void compressBlock ( EState* s, Bool is_last_block )
{
if (s->nblock > 0) {
BZ_FINALISE_CRC ( s->blockCRC );
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
s->combinedCRC ^= s->blockCRC;
if (s->blockNo > 1) s->numZ = 0;
if (s->verbosity >= 2)
VPrintf4( " block %d: crc = 0x%8x, "
"combined CRC = 0x%8x, size = %d\n",
s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
blockSort ( s );
}
/*-- If this is the first block, create the stream header. --*/
if (s->blockNo == 1) {
bsInitWrite ( s );
bsPutUChar ( s, 'B' );
bsPutUChar ( s, 'Z' );
bsPutUChar ( s, 'h' );
bsPutUChar ( s, '0' + s->blockSize100k );
}
if (s->nblock > 0) {
bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 );
bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 );
bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 );
/*-- Now the block's CRC, so it is in a known place. --*/
bsPutUInt32 ( s, s->blockCRC );
/*-- Now a single bit indicating randomisation. --*/
if (s->blockRandomised) {
bsW(s,1,1); s->nBlocksRandomised++;
} else
bsW(s,1,0);
bsW ( s, 24, s->origPtr );
generateMTFValues ( s );
sendMTFValues ( s );
}
/*-- If this is the last block, add the stream trailer. --*/
if (is_last_block) {
if (s->verbosity >= 2 && s->nBlocksRandomised > 0)
VPrintf2 ( " %d block%s needed randomisation\n",
s->nBlocksRandomised,
s->nBlocksRandomised == 1 ? "" : "s" );
bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 );
bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 );
bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
bsPutUInt32 ( s, s->combinedCRC );
if (s->verbosity >= 2)
VPrintf1( " final combined CRC = 0x%x\n ", s->combinedCRC );
bsFinishWrite ( s );
}
}
/*-------------------------------------------------------------*/
/*--- end compress.c ---*/
/*-------------------------------------------------------------*/

View file

@ -1,145 +0,0 @@
#pragma prototyped
/*-------------------------------------------------------------*/
/*--- Table for doing CRCs ---*/
/*--- crctable.c ---*/
/*-------------------------------------------------------------*/
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
Copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0c of 18 October 1998
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
#include "bzhdr.h"
/*--
I think this is an implementation of the AUTODIN-II,
Ethernet & FDDI 32-bit CRC standard. Vaguely derived
from code by Rob Warnock, in Section 51 of the
comp.compression FAQ.
--*/
UInt32 crc32Table[256] = {
/*-- Ugly, innit? --*/
0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
};
/*-------------------------------------------------------------*/
/*--- end crctable.c ---*/
/*-------------------------------------------------------------*/

View file

@ -1,637 +0,0 @@
#pragma prototyped
/*-------------------------------------------------------------*/
/*--- Decompression machinery ---*/
/*--- decompress.c ---*/
/*-------------------------------------------------------------*/
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
Copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0c of 18 October 1998
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
#include "bzhdr.h"
/*---------------------------------------------------*/
static
void makeMaps_d ( DState* s )
{
Int32 i;
s->nInUse = 0;
for (i = 0; i < 256; i++)
if (s->inUse[i]) {
s->seqToUnseq[s->nInUse] = i;
s->nInUse++;
}
}
/*---------------------------------------------------*/
#define RETURN(rrr) \
{ retVal = rrr; goto save_state_and_return; };
#define GET_BITS(lll,vvv,nnn) \
case lll: s->state = lll; \
while (True) { \
if (s->bsLive >= nnn) { \
UInt32 v; \
v = (s->bsBuff >> \
(s->bsLive-nnn)) & ((1 << nnn)-1); \
s->bsLive -= nnn; \
vvv = v; \
break; \
} \
if (s->strm->avail_in == 0) RETURN(BZ_OK); \
s->bsBuff \
= (s->bsBuff << 8) | \
((UInt32) \
(*((UChar*)(s->strm->next_in)))); \
s->bsLive += 8; \
s->strm->next_in++; \
s->strm->avail_in--; \
s->strm->total_in++; \
}
#define GET_UCHAR(lll,uuu) \
GET_BITS(lll,uuu,8)
#define GET_BIT(lll,uuu) \
GET_BITS(lll,uuu,1)
/*---------------------------------------------------*/
#define GET_MTF_VAL(label1,label2,lval) \
{ \
if (groupPos == 0) { \
groupNo++; \
groupPos = BZ_G_SIZE; \
gSel = s->selector[groupNo]; \
gMinlen = s->minLens[gSel]; \
gLimit = &(s->limit[gSel][0]); \
gPerm = &(s->perm[gSel][0]); \
gBase = &(s->base[gSel][0]); \
} \
groupPos--; \
zn = gMinlen; \
GET_BITS(label1, zvec, zn); \
while (zvec > gLimit[zn]) { \
zn++; \
GET_BIT(label2, zj); \
zvec = (zvec << 1) | zj; \
}; \
lval = gPerm[zvec - gBase[zn]]; \
}
/*---------------------------------------------------*/
Int32 decompress ( DState* s )
{
UChar uc;
Int32 retVal;
Int32 minLen, maxLen;
bz_stream* strm = s->strm;
/* stuff that needs to be saved/restored */
Int32 i ;
Int32 j;
Int32 t;
Int32 alphaSize;
Int32 nGroups;
Int32 nSelectors;
Int32 EOB;
Int32 groupNo;
Int32 groupPos;
Int32 nextSym;
Int32 nblockMAX;
Int32 nblock;
Int32 es;
Int32 N;
Int32 curr;
Int32 zt;
Int32 zn;
Int32 zvec;
Int32 zj;
Int32 gSel;
Int32 gMinlen;
Int32* gLimit;
Int32* gBase;
Int32* gPerm;
if (s->state == BZ_X_MAGIC_1) {
/*initialise the save area*/
s->save_i = 0;
s->save_j = 0;
s->save_t = 0;
s->save_alphaSize = 0;
s->save_nGroups = 0;
s->save_nSelectors = 0;
s->save_EOB = 0;
s->save_groupNo = 0;
s->save_groupPos = 0;
s->save_nextSym = 0;
s->save_nblockMAX = 0;
s->save_nblock = 0;
s->save_es = 0;
s->save_N = 0;
s->save_curr = 0;
s->save_zt = 0;
s->save_zn = 0;
s->save_zvec = 0;
s->save_zj = 0;
s->save_gSel = 0;
s->save_gMinlen = 0;
s->save_gLimit = NULL;
s->save_gBase = NULL;
s->save_gPerm = NULL;
}
/*restore from the save area*/
i = s->save_i;
j = s->save_j;
t = s->save_t;
alphaSize = s->save_alphaSize;
nGroups = s->save_nGroups;
nSelectors = s->save_nSelectors;
EOB = s->save_EOB;
groupNo = s->save_groupNo;
groupPos = s->save_groupPos;
nextSym = s->save_nextSym;
nblockMAX = s->save_nblockMAX;
nblock = s->save_nblock;
es = s->save_es;
N = s->save_N;
curr = s->save_curr;
zt = s->save_zt;
zn = s->save_zn;
zvec = s->save_zvec;
zj = s->save_zj;
gSel = s->save_gSel;
gMinlen = s->save_gMinlen;
gLimit = s->save_gLimit;
gBase = s->save_gBase;
gPerm = s->save_gPerm;
retVal = BZ_OK;
switch (s->state) {
GET_UCHAR(BZ_X_MAGIC_1, uc);
if (uc != 'B') RETURN(BZ_DATA_ERROR_MAGIC);
GET_UCHAR(BZ_X_MAGIC_2, uc);
if (uc != 'Z') RETURN(BZ_DATA_ERROR_MAGIC);
GET_UCHAR(BZ_X_MAGIC_3, uc)
if (uc != 'h') RETURN(BZ_DATA_ERROR_MAGIC);
GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
if (s->blockSize100k < '1' ||
s->blockSize100k > '9') RETURN(BZ_DATA_ERROR_MAGIC);
s->blockSize100k -= '0';
if (s->smallDecompress) {
s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
s->ll4 = BZALLOC(
((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar)
);
if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
} else {
s->tt = BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
if (s->tt == NULL) RETURN(BZ_MEM_ERROR);
}
GET_UCHAR(BZ_X_BLKHDR_1, uc);
if (uc == 0x17) goto endhdr_2;
if (uc != 0x31) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_BLKHDR_2, uc);
if (uc != 0x41) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_BLKHDR_3, uc);
if (uc != 0x59) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_BLKHDR_4, uc);
if (uc != 0x26) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_BLKHDR_5, uc);
if (uc != 0x53) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_BLKHDR_6, uc);
if (uc != 0x59) RETURN(BZ_DATA_ERROR);
s->currBlockNo++;
if (s->verbosity >= 2)
VPrintf1 ( "\n [%d: huff+mtf ", s->currBlockNo );
s->storedBlockCRC = 0;
GET_UCHAR(BZ_X_BCRC_1, uc);
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
GET_UCHAR(BZ_X_BCRC_2, uc);
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
GET_UCHAR(BZ_X_BCRC_3, uc);
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
GET_UCHAR(BZ_X_BCRC_4, uc);
s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc);
GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1);
s->origPtr = 0;
GET_UCHAR(BZ_X_ORIGPTR_1, uc);
s->origPtr = (s->origPtr << 8) | ((Int32)uc);
GET_UCHAR(BZ_X_ORIGPTR_2, uc);
s->origPtr = (s->origPtr << 8) | ((Int32)uc);
GET_UCHAR(BZ_X_ORIGPTR_3, uc);
s->origPtr = (s->origPtr << 8) | ((Int32)uc);
/*--- Receive the mapping table ---*/
for (i = 0; i < 16; i++) {
GET_BIT(BZ_X_MAPPING_1, uc);
if (uc == 1)
s->inUse16[i] = True; else
s->inUse16[i] = False;
}
for (i = 0; i < 256; i++) s->inUse[i] = False;
for (i = 0; i < 16; i++)
if (s->inUse16[i])
for (j = 0; j < 16; j++) {
GET_BIT(BZ_X_MAPPING_2, uc);
if (uc == 1) s->inUse[i * 16 + j] = True;
}
makeMaps_d ( s );
alphaSize = s->nInUse+2;
/*--- Now the selectors ---*/
GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
for (i = 0; i < nSelectors; i++) {
j = 0;
while (True) {
GET_BIT(BZ_X_SELECTOR_3, uc);
if (uc == 0) break;
j++;
if (j > 5) RETURN(BZ_DATA_ERROR);
}
s->selectorMtf[i] = j;
}
/*--- Undo the MTF values for the selectors. ---*/
{
UChar pos[BZ_N_GROUPS], tmp, v;
for (v = 0; v < nGroups; v++) pos[v] = v;
for (i = 0; i < nSelectors; i++) {
v = s->selectorMtf[i];
tmp = pos[v];
while (v > 0) { pos[v] = pos[v-1]; v--; }
pos[0] = tmp;
s->selector[i] = tmp;
}
}
/*--- Now the coding tables ---*/
for (t = 0; t < nGroups; t++) {
GET_BITS(BZ_X_CODING_1, curr, 5);
for (i = 0; i < alphaSize; i++) {
while (True) {
if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR);
GET_BIT(BZ_X_CODING_2, uc);
if (uc == 0) break;
GET_BIT(BZ_X_CODING_3, uc);
if (uc == 0) curr++; else curr--;
}
s->len[t][i] = curr;
}
}
/*--- Create the Huffman decoding tables ---*/
for (t = 0; t < nGroups; t++) {
minLen = 32;
maxLen = 0;
for (i = 0; i < alphaSize; i++) {
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
if (s->len[t][i] < minLen) minLen = s->len[t][i];
}
hbCreateDecodeTables (
&(s->limit[t][0]),
&(s->base[t][0]),
&(s->perm[t][0]),
&(s->len[t][0]),
minLen, maxLen, alphaSize
);
s->minLens[t] = minLen;
}
/*--- Now the MTF values ---*/
EOB = s->nInUse+1;
nblockMAX = 100000 * s->blockSize100k;
groupNo = -1;
groupPos = 0;
for (i = 0; i <= 255; i++) s->unzftab[i] = 0;
/*-- MTF init --*/
{
Int32 ii, jj, kk;
kk = MTFA_SIZE-1;
for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) {
for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
s->mtfa[kk] = (UChar)(ii * MTFL_SIZE + jj);
kk--;
}
s->mtfbase[ii] = kk + 1;
}
}
/*-- end MTF init --*/
nblock = 0;
GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym);
while (True) {
if (nextSym == EOB) break;
if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
es = -1;
N = 1;
do {
if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
if (nextSym == BZ_RUNB) es = es + (1+1) * N;
N = N * 2;
GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
}
while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
es++;
uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
s->unzftab[uc] += es;
if (s->smallDecompress)
while (es > 0) {
s->ll16[nblock] = (UInt16)uc;
nblock++;
es--;
}
else
while (es > 0) {
s->tt[nblock] = (UInt32)uc;
nblock++;
es--;
};
if (nblock > nblockMAX) RETURN(BZ_DATA_ERROR);
continue;
} else {
if (nblock > nblockMAX) RETURN(BZ_DATA_ERROR);
/*-- uc = MTF ( nextSym-1 ) --*/
{
Int32 ii, jj, kk, pp, lno, off;
UInt32 nn;
nn = (UInt32)(nextSym - 1);
if (nn < MTFL_SIZE) {
/* avoid general-case expense */
pp = s->mtfbase[0];
uc = s->mtfa[pp+nn];
while (nn > 3) {
Int32 z = pp+nn;
s->mtfa[(z) ] = s->mtfa[(z)-1];
s->mtfa[(z)-1] = s->mtfa[(z)-2];
s->mtfa[(z)-2] = s->mtfa[(z)-3];
s->mtfa[(z)-3] = s->mtfa[(z)-4];
nn -= 4;
}
while (nn > 0) {
s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
};
s->mtfa[pp] = uc;
} else {
/* general case */
lno = nn / MTFL_SIZE;
off = nn % MTFL_SIZE;
pp = s->mtfbase[lno] + off;
uc = s->mtfa[pp];
while (pp > s->mtfbase[lno]) {
s->mtfa[pp] = s->mtfa[pp-1]; pp--;
};
s->mtfbase[lno]++;
while (lno > 0) {
s->mtfbase[lno]--;
s->mtfa[s->mtfbase[lno]]
= s->mtfa[s->mtfbase[lno-1] + MTFL_SIZE - 1];
lno--;
}
s->mtfbase[0]--;
s->mtfa[s->mtfbase[0]] = uc;
if (s->mtfbase[0] == 0) {
kk = MTFA_SIZE-1;
for (ii = 256 / MTFL_SIZE-1; ii >= 0; ii--) {
for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
s->mtfa[kk] = s->mtfa[s->mtfbase[ii] + jj];
kk--;
}
s->mtfbase[ii] = kk + 1;
}
}
}
}
/*-- end uc = MTF ( nextSym-1 ) --*/
s->unzftab[s->seqToUnseq[uc]]++;
if (s->smallDecompress)
s->ll16[nblock] = (UInt16)(s->seqToUnseq[uc]); else
s->tt[nblock] = (UInt32)(s->seqToUnseq[uc]);
nblock++;
GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym);
continue;
}
}
s->state_out_len = 0;
s->state_out_ch = 0;
BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
s->state = BZ_X_OUTPUT;
if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
/*-- Set up cftab to facilitate generation of T^(-1) --*/
s->cftab[0] = 0;
for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
if (s->smallDecompress) {
/*-- Make a copy of cftab, used in generation of T --*/
for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i];
/*-- compute the T vector --*/
for (i = 0; i < nblock; i++) {
uc = (UChar)(s->ll16[i]);
SET_LL(i, s->cftabCopy[uc]);
s->cftabCopy[uc]++;
}
/*-- Compute T^(-1) by pointer reversal on T --*/
i = s->origPtr;
j = GET_LL(i);
do {
Int32 tmp = GET_LL(j);
SET_LL(j, i);
i = j;
j = tmp;
}
while (i != s->origPtr);
s->tPos = s->origPtr;
s->nblock_used = 0;
if (s->blockRandomised) {
BZ_RAND_INIT_MASK;
BZ_GET_SMALL(s->k0); s->nblock_used++;
BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
} else {
BZ_GET_SMALL(s->k0); s->nblock_used++;
}
} else {
/*-- compute the T^(-1) vector --*/
for (i = 0; i < nblock; i++) {
uc = (UChar)(s->tt[i] & 0xff);
s->tt[s->cftab[uc]] |= (i << 8);
s->cftab[uc]++;
}
s->tPos = s->tt[s->origPtr] >> 8;
s->nblock_used = 0;
if (s->blockRandomised) {
BZ_RAND_INIT_MASK;
BZ_GET_FAST(s->k0); s->nblock_used++;
BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK;
} else {
BZ_GET_FAST(s->k0); s->nblock_used++;
}
}
RETURN(BZ_OK);
endhdr_2:
GET_UCHAR(BZ_X_ENDHDR_2, uc);
if (uc != 0x72) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_ENDHDR_3, uc);
if (uc != 0x45) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_ENDHDR_4, uc);
if (uc != 0x38) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_ENDHDR_5, uc);
if (uc != 0x50) RETURN(BZ_DATA_ERROR);
GET_UCHAR(BZ_X_ENDHDR_6, uc);
if (uc != 0x90) RETURN(BZ_DATA_ERROR);
s->storedCombinedCRC = 0;
GET_UCHAR(BZ_X_CCRC_1, uc);
s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
GET_UCHAR(BZ_X_CCRC_2, uc);
s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
GET_UCHAR(BZ_X_CCRC_3, uc);
s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
GET_UCHAR(BZ_X_CCRC_4, uc);
s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc);
s->state = BZ_X_IDLE;
RETURN(BZ_STREAM_END);
default: AssertH ( False, 4001 );
}
AssertH ( False, 4002 );
save_state_and_return:
s->save_i = i;
s->save_j = j;
s->save_t = t;
s->save_alphaSize = alphaSize;
s->save_nGroups = nGroups;
s->save_nSelectors = nSelectors;
s->save_EOB = EOB;
s->save_groupNo = groupNo;
s->save_groupPos = groupPos;
s->save_nextSym = nextSym;
s->save_nblockMAX = nblockMAX;
s->save_nblock = nblock;
s->save_es = es;
s->save_N = N;
s->save_curr = curr;
s->save_zt = zt;
s->save_zn = zn;
s->save_zvec = zvec;
s->save_zj = zj;
s->save_gSel = gSel;
s->save_gMinlen = gMinlen;
s->save_gLimit = gLimit;
s->save_gBase = gBase;
s->save_gPerm = gPerm;
return retVal;
}
/*-------------------------------------------------------------*/
/*--- end decompress.c ---*/
/*-------------------------------------------------------------*/

View file

@ -1,229 +0,0 @@
#pragma prototyped
/*-------------------------------------------------------------*/
/*--- Huffman coding low-level stuff ---*/
/*--- huffman.c ---*/
/*-------------------------------------------------------------*/
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
Copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0c of 18 October 1998
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
#include "bzhdr.h"
/*---------------------------------------------------*/
#define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
#define DEPTHOF(zz1) ((zz1) & 0x000000ff)
#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
#define ADDWEIGHTS(zw1,zw2) \
(WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
(1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
#define UPHEAP(z) \
{ \
Int32 zz, tmp; \
zz = z; tmp = heap[zz]; \
while (weight[tmp] < weight[heap[zz >> 1]]) { \
heap[zz] = heap[zz >> 1]; \
zz >>= 1; \
} \
heap[zz] = tmp; \
}
#define DOWNHEAP(z) \
{ \
Int32 zz, yy, tmp; \
zz = z; tmp = heap[zz]; \
while (True) { \
yy = zz << 1; \
if (yy > nHeap) break; \
if (yy < nHeap && \
weight[heap[yy+1]] < weight[heap[yy]]) \
yy++; \
if (weight[tmp] < weight[heap[yy]]) break; \
heap[zz] = heap[yy]; \
zz = yy; \
} \
heap[zz] = tmp; \
}
/*---------------------------------------------------*/
void hbMakeCodeLengths ( UChar *len,
Int32 *freq,
Int32 alphaSize,
Int32 maxLen )
{
/*--
Nodes and heap entries run from 1. Entry 0
for both the heap and nodes is a sentinel.
--*/
Int32 nNodes, nHeap, n1, n2, i, j, k;
Bool tooLong;
Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
for (i = 0; i < alphaSize; i++)
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
while (True) {
nNodes = alphaSize;
nHeap = 0;
heap[0] = 0;
weight[0] = 0;
parent[0] = -2;
for (i = 1; i <= alphaSize; i++) {
parent[i] = -1;
nHeap++;
heap[nHeap] = i;
UPHEAP(nHeap);
}
AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
while (nHeap > 1) {
n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
nNodes++;
parent[n1] = parent[n2] = nNodes;
weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
parent[nNodes] = -1;
nHeap++;
heap[nHeap] = nNodes;
UPHEAP(nHeap);
}
AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
tooLong = False;
for (i = 1; i <= alphaSize; i++) {
j = 0;
k = i;
while (parent[k] >= 0) { k = parent[k]; j++; }
len[i-1] = j;
if (j > maxLen) tooLong = True;
}
if (! tooLong) break;
for (i = 1; i < alphaSize; i++) {
j = weight[i] >> 8;
j = 1 + (j / 2);
weight[i] = j << 8;
}
}
}
/*---------------------------------------------------*/
void hbAssignCodes ( Int32 *code,
UChar *length,
Int32 minLen,
Int32 maxLen,
Int32 alphaSize )
{
Int32 n, vec, i;
vec = 0;
for (n = minLen; n <= maxLen; n++) {
for (i = 0; i < alphaSize; i++)
if (length[i] == n) { code[i] = vec; vec++; };
vec <<= 1;
}
}
/*---------------------------------------------------*/
void hbCreateDecodeTables ( Int32 *limit,
Int32 *base,
Int32 *perm,
UChar *length,
Int32 minLen,
Int32 maxLen,
Int32 alphaSize )
{
Int32 pp, i, j, vec;
pp = 0;
for (i = minLen; i <= maxLen; i++)
for (j = 0; j < alphaSize; j++)
if (length[j] == i) { perm[pp] = j; pp++; };
for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
vec = 0;
for (i = minLen; i <= maxLen; i++) {
vec += (base[i+1] - base[i]);
limit[i] = vec-1;
vec <<= 1;
}
for (i = minLen + 1; i <= maxLen; i++)
base[i] = ((limit[i-1] + 1) << 1) - base[i];
}
/*-------------------------------------------------------------*/
/*--- end huffman.c ---*/
/*-------------------------------------------------------------*/

View file

@ -1,125 +0,0 @@
#pragma prototyped
/*-------------------------------------------------------------*/
/*--- Table for randomising repetitive blocks ---*/
/*--- randtable.c ---*/
/*-------------------------------------------------------------*/
/*--
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
Copyright (C) 1996-1998 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Guildford, Surrey, UK.
jseward@acm.org
bzip2/libbzip2 version 0.9.0c of 18 October 1998
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
#include "bzhdr.h"
/*---------------------------------------------*/
Int32 rNums[512] = {
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
936, 638
};
/*-------------------------------------------------------------*/
/*--- end randtable.c ---*/
/*-------------------------------------------------------------*/

View file

@ -1,220 +0,0 @@
/***********************************************************************
* *
* This software is part of the zlib package *
* Copyright (c) 1996-2003 Jean-loup Gailly and Mark Adler *
* *
* This software is provided 'as-is', without any express or implied *
* warranty. In no event will the authors be held liable for any *
* damages arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any *
* purpose, including commercial applications, and to alter it and *
* redistribute it freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; *
* you must not claim that you wrote the original software. If *
* you use this software in a product, an acknowledgment in the *
* product documentation would be appreciated but is not *
* required. *
* *
* 2. Altered source versions must be plainly marked as such, *
* and must not be misrepresented as being the original *
* software. *
* *
* 3. This notice may not be removed or altered from any source *
* distribution. *
* *
* This software is provided "as-is", without any express or implied *
* warranty. In no event will the authors be held liable for any damages*
* arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose,*
* including commercial applications, and to alter it and redistribute i*
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must n*
* claim that you wrote the original software. If you use this softwa*
* in a product, an acknowledgment in the product documentation would*
* be appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must n*
* be misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source *
* distribution. *
* *
* Julian R Seward *
* *
***********************************************************************/
#pragma prototyped
/*
* sfio bzip discipline
*/
#include <sfio_t.h>
#include <ast.h>
#include <bzlib.h>
#include <sfdcbzip.h>
#define bzsync(p,o) (-1)
typedef struct
{
Sfdisc_t disc; /* sfio discipline */
Bz_t* bz; /* bz handle */
} Sfbzip_t;
/*
* bzip exception handler
* free on close
*/
static int
sfbzexcept(Sfio_t* sp, int op, void* val, Sfdisc_t* dp)
{
register Sfbzip_t* bz = (Sfbzip_t*)dp;
int r;
NoP(sp);
#if 1
{
static char aha[] = "AHA sfdcbzip event 0\n";
static int init;
if (!init)
init = getenv("SFBZ_DEBUG") ? 1 : -1;
if (init > 0)
{
aha[sizeof(aha) - 3] = '0' + op;
write(2, aha, sizeof(aha) - 1);
}
}
#endif
switch (op)
{
case SF_ATEXIT:
sfdisc(sp, SF_POPDISC);
return 0;
case SF_CLOSING:
case SF_DPOP:
case SF_FINAL:
if (bz->bz)
{
r = bzclose(bz->bz) ? -1 : 0;
bz->bz = 0;
}
else
r = 0;
if (op != SF_CLOSING)
free(dp);
return r;
case SF_DBUFFER:
return 1;
case SF_READ:
case SF_WRITE:
return *((ssize_t*)val) < 0 ? -1 : 0;
case SF_SYNC:
return val ? 0 : bzflush(bz->bz);
case SFBZ_HANDLE:
return (*((Bz_t**)val) = bz->bz) ? 1 : -1;
case SFBZ_GETPOS:
return (*((Sfoff_t*)val) = bzsync(bz->bz, (z_off_t)(-1))) == -1 ? -1 : 0;
case SFBZ_SETPOS:
return bzsync(bz->bz, (z_off_t)(*((Sfoff_t*)val))) == -1 ? -1 : 0;
}
return 0;
}
/*
* sfio bzip discipline read
*/
static ssize_t
sfbzread(Sfio_t* fp, Void_t* buf, size_t size, Sfdisc_t* dp)
{
register Sfbzip_t* bz = (Sfbzip_t*)dp;
return bzread(bz->bz, buf, size);
}
/*
* sfio bzip discipline write
*/
static ssize_t
sfbzwrite(Sfio_t* fp, const Void_t* buf, size_t size, Sfdisc_t* dp)
{
register Sfbzip_t* bz = (Sfbzip_t*)dp;
return (bzwrite(bz->bz, (void*)buf, size) < 0) ? -1 : size;
}
/*
* create and push the sfio bzip discipline
*
* (flags&SFBZ_VERIFY) return
* >0 is a bzip file
* 0 not a bzip file
* <0 error
* otherwise return
* >0 discipline pushed
* 0 discipline not needed
* <0 error
*/
int
sfdcbzip(Sfio_t* sp, int flags)
{
char* m;
Sfbzip_t* bz;
char mode[10];
if (sfset(sp, 0, 0) & SF_READ)
{
register unsigned char* s;
register int n;
/*
* peek the first 4 bytes to verify the magic
*
* BZh[0-9] sfdcbzip bzip
*/
if (!(n = sfset(sp, 0, 0) & SF_SHARE))
sfset(sp, SF_SHARE, 1);
s = (unsigned char*)sfreserve(sp, 4, 1);
if (!n)
sfset(sp, SF_SHARE, 0);
if (!s)
return -1;
n = s[0] == 'B' && s[1] == 'Z' && s[2] == 'h' && (s[3] >= '0' && s[3] <= '9');
sfread(sp, s, 0);
if (!n || (flags & SFBZ_VERIFY))
return n;
}
else if (flags & SFBZ_VERIFY)
return -1;
if (!(bz = newof(0, Sfbzip_t, 1, 0)))
return -1;
bz->disc.exceptf = sfbzexcept;
if (sfset(sp, 0, 0) & SF_READ)
bz->disc.readf = sfbzread;
else
bz->disc.writef = sfbzwrite;
m = mode;
*m++ = (sfset(sp, 0, 0) & SF_READ) ? 'r' : 'w';
*m++ = 'o';
if ((flags &= 0xf) > 0 && flags <= 9)
*m++ = '0' + flags;
*m = 0;
if (sfdisc(sp, &bz->disc) != &bz->disc || !(bz->bz = bzdopen(sffileno(sp), mode)))
{
free(bz);
return -1;
}
sfsetbuf(sp, NiL, SF_BUFSIZE);
if (!(sfset(sp, 0, 0) & SF_READ))
sfset(sp, SF_IOCHECK, 1);
return 1;
}

View file

@ -1,74 +0,0 @@
/***********************************************************************
* *
* This software is part of the zlib package *
* Copyright (c) 1996-1999 Jean-loup Gailly and Mark Adler *
* *
* This software is provided 'as-is', without any express or implied *
* warranty. In no event will the authors be held liable for any *
* damages arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any *
* purpose, including commercial applications, and to alter it and *
* redistribute it freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; *
* you must not claim that you wrote the original software. If *
* you use this software in a product, an acknowledgment in the *
* product documentation would be appreciated but is not *
* required. *
* *
* 2. Altered source versions must be plainly marked as such, *
* and must not be misrepresented as being the original *
* software. *
* *
* 3. This notice may not be removed or altered from any source *
* distribution. *
* *
* This software is provided "as-is", without any express or implied *
* warranty. In no event will the authors be held liable for any damages*
* arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose,*
* including commercial applications, and to alter it and redistribute i*
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must n*
* claim that you wrote the original software. If you use this softwa*
* in a product, an acknowledgment in the product documentation would*
* be appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must n*
* be misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source *
* distribution. *
* *
* Julian R Seward *
* *
***********************************************************************/
#pragma prototyped
/*
* sfio bzip discipline interface
*/
#ifndef _SFDCBZIP_H
#define _SFDCBZIP_H
#include <sfdisc.h>
#define SFBZ_VERIFY 0x0010
#define SFBZ_HANDLE SFDCEVENT('B','Z',1)
#define SFBZ_GETPOS SFDCEVENT('B','Z',2)
#define SFBZ_SETPOS SFDCEVENT('B','Z',3)
#if _BLD_bz && defined(__EXPORT__)
#define extern __EXPORT__
#endif
extern int sfdcbzip(Sfio_t*, int);
#undef extern
#endif

View file

@ -1,15 +0,0 @@
:PACKAGE: ast
LICENSE = since=2003,author=gsf+dgk+kpv
CCFLAGS = $(CC.OPTIMIZE) $(CC.DLL)
codex 1.0 :LIBRARY: codex.c codexdata.c codexid.c codexlist.c \
codexcmp.c codexmeth.c codexadd.c codexnull.c \
codexgetpass.c codexpass.c codexsize.c \
code-rot13.c code-qp.c code-uu.c code-iconv.c \
-ldll
$(INCLUDEDIR) :INSTALLPROTO: codex.h
:: RELEASE NOTES

View file

@ -1,355 +0,0 @@
info mam static 00000 1994-07-17 make (AT&T Research) 5.7 2012-06-20
setv INSTALLROOT ../../..
setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast
setv PACKAGE_ast_LIB ${INSTALLROOT}/lib
setv PACKAGEROOT ../../../../..
setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS}
setv ARFLAGS rc
setv AS as
setv ASFLAGS
setv CC cc
setv mam_cc_FLAGS ${mam_cc_DLL}
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
setv COTEMP $$
setv CPIO cpio
setv CPIOFLAGS
setv CPP "${CC} -E"
setv F77 f77
setv HOSTCC ${CC}
setv IGNORE
setv LD ld
setv LDFLAGS
setv LEX lex
setv LEXFLAGS
setv LPR lpr
setv LPRFLAGS
setv M4FLAGS
setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
setv SHELL /bin/sh
setv SILENT
setv TAR tar
setv YACC yacc
setv YACCFLAGS -d
make ${PACKAGEROOT}/lib/package/ast.lic
done ${PACKAGEROOT}/lib/package/ast.lic
make install
make codex
make libcodex.a archive
make codex.req
exec - set -
exec - echo 'int main(){return 0;}' > 1.${COTEMP}.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -c 1.${COTEMP}.c &&
exec - x=`${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l'*' 2>&1 | sed -e 's/[][()+@?]/#/g' || :` &&
exec - {
exec - case "" in
exec - *?) echo " " ;;
exec - esac
exec - for i in codex dll ast
exec - do case $i in
exec - "codex"|codex)
exec - ;;
exec - *) if test -f ${INSTALLROOT}/lib/lib/$i
exec - then y=`cat ${INSTALLROOT}/lib/lib/$i`
exec - case $y in
exec - *-?*) echo "" $y ;;
exec - esac
exec - continue
exec - elif test ! -f ${INSTALLROOT}/lib/lib$i.a
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) continue ;;
exec - esac
exec - ;;
exec - esac
exec - fi
exec - ;;
exec - esac
exec - echo " -l$i"
exec - done
exec - } > codex.req
exec - rm -f 1.${COTEMP}.*
done codex.req generated
make codex.o
make codex.c
make ${PACKAGE_ast_INCLUDE}/namval.h implicit
make ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/prototyped.h dontcare
done ${PACKAGE_ast_INCLUDE}/namval.h
make codex.h implicit
make codexlib.h implicit
make ${PACKAGE_ast_INCLUDE}/debug.h implicit
make ${PACKAGE_ast_INCLUDE}/error.h implicit
make ${PACKAGE_ast_INCLUDE}/option.h implicit
make ${PACKAGE_ast_INCLUDE}/ast.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_api.h dontcare
make ${PACKAGE_ast_INCLUDE}/vmalloc.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_map.h dontcare
make ${PACKAGE_ast_INCLUDE}/endian.h implicit
make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
done ${PACKAGE_ast_INCLUDE}/bytesex.h dontcare
done ${PACKAGE_ast_INCLUDE}/endian.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_common.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
make ${PACKAGE_ast_INCLUDE}/regex.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
make ${PACKAGE_ast_INCLUDE}/wctype.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
make ${PACKAGE_ast_INCLUDE}/wchar.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
done ${PACKAGE_ast_INCLUDE}/wchar.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_wctype.h dontcare
done ${PACKAGE_ast_INCLUDE}/wctype.h dontcare
make ${PACKAGE_ast_INCLUDE}/stdio.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit
make ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio_s.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_stdio.h dontcare
done ${PACKAGE_ast_INCLUDE}/stdio.h dontcare
prev ${PACKAGE_ast_INCLUDE}/stdio.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_wchar.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/regex.h dontcare
make ${PACKAGE_ast_INCLUDE}/getopt.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_getopt.h dontcare
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/getopt.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_botch.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_botch.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_limits.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_limits.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_fcntl.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_fs.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_fs.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_fcntl.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_sys.h implicit
prev ${PACKAGE_ast_INCLUDE}/getopt.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_sys.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_lib.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_lib.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_std.h dontcare
done ${PACKAGE_ast_INCLUDE}/vmalloc.h dontcare
make ${PACKAGE_ast_INCLUDE}/sfio.h implicit
prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast.h dontcare
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/option.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/error.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/debug.h dontcare
done codexlib.h dontcare
prev ${PACKAGE_ast_INCLUDE}/error.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
done codex.h
make ${PACKAGE_ast_INCLUDE}/sfio_t.h implicit
prev ${PACKAGE_ast_INCLUDE}/sfio.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio_t.h
done codex.c
meta codex.o %.c>%.o codex.c codex
prev codex.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codex.c
done codex.o generated
make codexdata.o
make codexdata.c
prev codex.h implicit
done codexdata.c
meta codexdata.o %.c>%.o codexdata.c codexdata
prev codexdata.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexdata.c
done codexdata.o generated
make codexid.o
make codexid.c
prev codex.h implicit
done codexid.c
meta codexid.o %.c>%.o codexid.c codexid
prev codexid.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexid.c
done codexid.o generated
make codexlist.o
make codexlist.c
make ${PACKAGE_ast_INCLUDE}/dlldefs.h implicit
done ${PACKAGE_ast_INCLUDE}/dlldefs.h
prev codex.h implicit
done codexlist.c
meta codexlist.o %.c>%.o codexlist.c codexlist
prev codexlist.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexlist.c
done codexlist.o generated
make codexcmp.o
make codexcmp.c
prev codex.h implicit
done codexcmp.c
meta codexcmp.o %.c>%.o codexcmp.c codexcmp
prev codexcmp.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexcmp.c
done codexcmp.o generated
make codexmeth.o
make codexmeth.c
prev ${PACKAGE_ast_INCLUDE}/dlldefs.h implicit
prev codex.h implicit
done codexmeth.c
meta codexmeth.o %.c>%.o codexmeth.c codexmeth
prev codexmeth.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexmeth.c
done codexmeth.o generated
make codexadd.o
make codexadd.c
prev codex.h implicit
done codexadd.c
meta codexadd.o %.c>%.o codexadd.c codexadd
prev codexadd.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexadd.c
done codexadd.o generated
make codexnull.o
make codexnull.c
prev codex.h implicit
prev ${PACKAGE_ast_INCLUDE}/sfio_t.h implicit
done codexnull.c
meta codexnull.o %.c>%.o codexnull.c codexnull
prev codexnull.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexnull.c
done codexnull.o generated
make codexgetpass.o
make codexgetpass.c
make ${PACKAGE_ast_INCLUDE}/ast_tty.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_tty.h
make ${PACKAGE_ast_INCLUDE}/sig.h implicit
done ${PACKAGE_ast_INCLUDE}/sig.h
prev codex.h implicit
done codexgetpass.c
meta codexgetpass.o %.c>%.o codexgetpass.c codexgetpass
prev codexgetpass.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexgetpass.c
done codexgetpass.o generated
make codexpass.o
make codexpass.c
prev codex.h implicit
done codexpass.c
meta codexpass.o %.c>%.o codexpass.c codexpass
prev codexpass.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexpass.c
done codexpass.o generated
make codexsize.o
make codexsize.c
prev codex.h implicit
done codexsize.c
meta codexsize.o %.c>%.o codexsize.c codexsize
prev codexsize.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c codexsize.c
done codexsize.o generated
make code-rot13.o
make code-rot13.c
prev codex.h implicit
done code-rot13.c
meta code-rot13.o %.c>%.o code-rot13.c code-rot13
prev code-rot13.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c code-rot13.c
done code-rot13.o generated
make code-qp.o
make code-qp.c
make ${PACKAGE_ast_INCLUDE}/ccode.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_ccode.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_ccode.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ccode.h
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev codex.h implicit
done code-qp.c
meta code-qp.o %.c>%.o code-qp.c code-qp
prev code-qp.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c code-qp.c
done code-qp.o generated
make code-uu.o
make code-uu.c
prev codex.h implicit
done code-uu.c
meta code-uu.o %.c>%.o code-uu.c code-uu
prev code-uu.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c code-uu.c
done code-uu.o generated
make code-iconv.o
make code-iconv.c
make ${PACKAGE_ast_INCLUDE}/iconv.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_iconv.h implicit
prev ${PACKAGE_ast_INCLUDE}/ccode.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_iconv.h
done ${PACKAGE_ast_INCLUDE}/iconv.h
prev codex.h implicit
done code-iconv.c
meta code-iconv.o %.c>%.o code-iconv.c code-iconv
prev code-iconv.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_codex -c code-iconv.c
done code-iconv.o generated
exec - ${AR} rc libcodex.a codex.o codexdata.o codexid.o codexlist.o codexcmp.o codexmeth.o codexadd.o codexnull.o codexgetpass.o codexpass.o codexsize.o code-rot13.o code-qp.o code-uu.o code-iconv.o
exec - (ranlib libcodex.a) >/dev/null 2>&1 || true
done libcodex.a generated
done codex virtual
prev libcodex.a archive
make ${INSTALLROOT}/lib
exec - if silent test ! -d ${INSTALLROOT}/lib
exec - then mkdir -p ${INSTALLROOT}/lib
exec - fi
done ${INSTALLROOT}/lib generated
make ${INSTALLROOT}/lib/libcodex.a archive
prev ${INSTALLROOT}/lib
prev libcodex.a archive
exec - test '' = 'libcodex.a' || ${STDCMP} 2>/dev/null -s libcodex.a ${INSTALLROOT}/lib/libcodex.a || { ${STDMV} ${INSTALLROOT}/lib/libcodex.a ${INSTALLROOT}/lib/libcodex.a.old 2>/dev/null || true; ${STDCP} libcodex.a ${INSTALLROOT}/lib/libcodex.a ;}
exec - (ranlib ${INSTALLROOT}/lib/libcodex.a) >/dev/null 2>&1 || true
done ${INSTALLROOT}/lib/libcodex.a generated
make ${INSTALLROOT}/lib/lib
exec - if silent test ! -d ${INSTALLROOT}/lib/lib
exec - then mkdir -p ${INSTALLROOT}/lib/lib
exec - fi
done ${INSTALLROOT}/lib/lib generated
make ${INSTALLROOT}/lib/lib/codex
prev ${INSTALLROOT}/lib/lib
prev codex.req
exec - test '' = 'codex.req' || ${STDCMP} 2>/dev/null -s codex.req ${INSTALLROOT}/lib/lib/codex || { ${STDMV} ${INSTALLROOT}/lib/lib/codex ${INSTALLROOT}/lib/lib/codex.old 2>/dev/null || true; ${STDCP} codex.req ${INSTALLROOT}/lib/lib/codex ;}
done ${INSTALLROOT}/lib/lib/codex generated
make ${PACKAGE_ast_INCLUDE}
exec - if silent test ! -d ${PACKAGE_ast_INCLUDE}
exec - then mkdir -p ${PACKAGE_ast_INCLUDE}
exec - fi
done ${PACKAGE_ast_INCLUDE} generated
make ${PACKAGE_ast_INCLUDE}/codex.h
prev ${PACKAGE_ast_INCLUDE}
prev codex.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=2003,author=gsf+dgk+kpv' codex.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/codex.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/codex.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/codex.h generated
done install virtual
make test
done test dontcare virtual

View file

@ -1,12 +0,0 @@
codex.tst snarf uuencode tests, add { rot13 iconv }
recode uuencode to use -lcodex: meth->data may be exported by <uu.h>
recode iconv to use -lcodex
code-zip combine { code-huff code-explode code-inflate }
code-pzip pzip[:partition-file-path]
code-bzip pzip[:partition-file-path]
code-compress
code-bx snarf from libuu

View file

@ -1,23 +0,0 @@
10-01-15 code-uu.c: add uu-base64-string to encode with no newline separators
09-06-26 codex.h,codex.c: add Sfio_t* Codex_t.op for open/close/read/write apis
08-05-23 code-qp.c: avoid isprint()/iscntrl() for CC_NATIVE==CC_ASCII
07-09-26 code-uu.c: uu_sync() => flush() for encode only -- doh
07-09-22 code-uu.c: fix uu_read() partial reads
07-09-22 codex.c: handle PASSPHRASE=* as documented
07-09-22 codex.c: handle quoted parameter values
06-08-23 code-uu.c: fix remainder output *and* input bugs
05-09-25 add '^' equivalent to '|'
04-02-14 codex.c: SFDCNEXT() and SFDCPREV() now provided by <sfio_t.h>
04-01-11 codex.c: top level composition parse, handle CODEX_INVERT
04-01-10 codex.c: use CODEX_FLUSH to disable SF_SYNC before initf
04-01-09 prepare codex.h for possible { decodef encodef } addition
04-01-04 codexcmp.c: fix return value to match strcmp(3)
03-12-30 codexmeth.c: case-sensitive match on qualified name
03-12-26 add CODEX_OPTIONS='trace=method-name-pattern debug'
03-12-25 codex.c: pop intermediate disciplines on error
03-12-22 add "RETAIN" option for CODEX_RETAIN
add "SIZE=size" and alternative codexsize() for expected output size
03-12-18 add to ast -- still working on relationship with { -lvcodex -lz -lbz }
03-12-16 codexlib.c: add cache to codex()
03-12-15 { rot13 qp uu iconv } working
03-12-11 first code

View file

@ -1,257 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* character codeset coder
*/
#include <codex.h>
#include <iconv.h>
typedef struct State_s
{
iconv_t cvt;
char* bp;
char buf[SF_BUFSIZE];
} State_t;
static int
cc_options(Codexmeth_t* meth, Sfio_t* sp)
{
register iconv_list_t* ic;
register const char* p;
register int c;
for (ic = iconv_list(NiL); ic; ic = iconv_list(ic))
{
sfputc(sp, '[');
sfputc(sp, '+');
sfputc(sp, '\b');
p = ic->match;
if (*p == '(')
p++;
while (c = *p++)
{
if (c == ')' && !*p)
break;
if (c == '?' || c == ']')
sfputc(sp, c);
sfputc(sp, c);
}
sfputc(sp, '?');
p = ic->desc;
while (c = *p++)
{
if (c == ']')
sfputc(sp, c);
sfputc(sp, c);
}
sfputc(sp, ']');
}
return 0;
}
static int
cc_open(Codex_t* p, char* const args[], Codexnum_t flags)
{
State_t* state;
const char* src;
const char* dst;
iconv_t cvt;
dst = (src = args[2]) ? args[3] : 0;
if (flags & CODEX_DECODE)
{
if (!src)
{
if (p->disc->errorf)
(*p->disc->errorf)(NiL, p->disc, 2, "%s: source codeset option must be specified", p->meth->name);
return -1;
}
}
else
{
if (!src)
{
if (p->disc->errorf)
(*p->disc->errorf)(NiL, p->disc, 2, "%s: destination codeset option must be specified", p->meth->name);
return -1;
}
if (!dst)
{
dst = src;
src = 0;
}
}
if ((cvt = iconv_open(dst, src)) == (iconv_t)(-1))
{
if (p->disc->errorf)
{
if ((cvt = iconv_open("utf-8", src)) == (iconv_t)(-1))
{
(*p->disc->errorf)(NiL, p->disc, 2, "%s: %s: unknown source codeset", p->meth->name, src);
return -1;
}
iconv_close(cvt);
if ((cvt = iconv_open(dst, "utf-8")) == (iconv_t)(-1))
{
(*p->disc->errorf)(NiL, p->disc, 2, "%s: %s: unknown destination codeset", p->meth->name, dst);
return -1;
}
iconv_close(cvt);
(*p->disc->errorf)(NiL, p->disc, 2, "%s: cannot convert from %s to %s", p->meth->name, src, dst);
}
return -1;
}
if (!(state = newof(0, State_t, 1, 0)))
{
if (p->disc->errorf)
(*p->disc->errorf)(NiL, p->disc, 2, "out of space");
iconv_close(cvt);
return 0;
}
state->cvt = cvt;
state->bp = state->buf;
p->data = state;
return 0;
}
static int
cc_close(Codex_t* p)
{
State_t* state = (State_t*)p->data;
int r;
if (!state)
r = -1;
else
{
r = iconv_close(state->cvt);
free(state);
}
return r;
}
static ssize_t
cc_read(Sfio_t* sp, void* buf, size_t n, Sfdisc_t* disc)
{
register State_t* state = (State_t*)((Codex_t*)disc)->data;
char* fb;
char* tb;
size_t fn;
size_t tn;
ssize_t r;
fn = sizeof(state->buf) - (state->bp - state->buf);
if (n < fn)
fn = n;
if ((r = sfrd(sp, state->bp, fn, disc)) <= 0)
return (state->bp > state->buf) ? -1 : r;
fb = state->buf;
fn = r + (state->bp - state->buf);
tb = buf;
tn = n;
n = 0;
while (fn > 0 && tn > 0)
{
if ((r = iconv(state->cvt, &fb, &fn, &tb, &tn)) == -1)
{
if (!n)
n = -1;
break;
}
n += r;
}
if (fn && fb > state->buf)
{
tb = state->buf;
while (fn--)
*tb++ = *fb++;
state->bp = tb;
}
return n;
}
static ssize_t
cc_write(Sfio_t* sp, const void* buf, size_t n, Sfdisc_t* disc)
{
register State_t* state = (State_t*)((Codex_t*)disc)->data;
char* fb;
char* tb;
size_t fn;
size_t tn;
size_t r;
fb = (char*)buf;
fn = n;
n = 0;
while (fn > 0)
{
tb = (char*)state->buf;
tn = sizeof(buf);
if ((r = iconv(state->cvt, &fb, &fn, &tb, &tn)) == (size_t)(-1))
return n ? n : -1;
n += r;
if (sfwr(sp, state->buf, r, disc) != r)
return n ? n : -1;
}
return n;
}
static int
cc_sync(Codex_t* p)
{
mbinit();
return 0;
}
Codexmeth_t codex_iconv =
{
"iconv",
"iconv character codeset conversion. One or two character codeset"
" options must be specified. Two options specify the source and"
" destination codesets. One option specifies the decode source or"
" encode destination codeset; the implied second codeset defaults"
" to \bnative\b.",
"[+(version)?codex-iconv (AT&T Research) 2000-05-09]"
"[+(author)?Glenn Fowler <gsf@research.att.com>]",
CODEX_DECODE|CODEX_ENCODE|CODEX_ICONV,
cc_options,
0,
cc_open,
cc_close,
cc_sync,
cc_sync,
cc_read,
cc_write,
cc_sync,
0,
0,
0,
0,
CODEXNEXT(iconv)
};
CODEXLIB(iconv)

View file

@ -1,313 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* quoted printable coder
*/
#include <codex.h>
#include <ctype.h>
#include <ccode.h>
#define LINE 76
#define BUFFER SF_BUFSIZE
typedef struct State_s
{
Codex_t* codex;
unsigned char* bp;
unsigned char* be;
unsigned char* pp;
unsigned char prv[5];
short xxx;
short xeh[UCHAR_MAX+1];
int col;
unsigned char buf[LINE + BUFFER + 1];
} State_t;
static const char hex[] = "0123456789ABCDEFabcdef";
#define GETCHAR(p) ((p)->bp < (p)->be ? (int)*(p)->bp++ : fill(p))
#define PUTCHAR(p,c) ((p)->bp < (p)->be ? (int)(*(p)->bp++=(c)) : flush(p,c))
static int
fill(State_t* state)
{
ssize_t r;
state->bp = state->buf + LINE;
if ((r = sfrd(state->codex->sp, state->bp, BUFFER, &state->codex->sfdisc)) <= 0)
{
state->be = state->bp;
return EOF;
}
state->be = state->bp + r;
return *state->bp++;
}
static int
flush(register State_t* state, int c)
{
size_t n;
if (c < 0 && state->col)
{
state->col = 0;
PUTCHAR(state, '=');
PUTCHAR(state, '\n');
}
if (state->bp && (n = state->bp - state->buf) && sfwr(state->codex->sp, state->buf, n, &state->codex->sfdisc) != n)
return EOF;
state->be = (state->bp = state->buf) + sizeof(state->buf);
if (c >= 0)
*state->bp++ = c;
return 0;
}
static int
qp_open(Codex_t* p, char* const args[], Codexnum_t flags)
{
register State_t* state;
register int i;
if (!(state = newof(0, State_t, 1, 0)))
{
if (p->disc->errorf)
(*p->disc->errorf)(NiL, p->disc, 2, "out of space");
return -1;
}
if (flags & CODEX_DECODE)
{
for (i = -1; i < elementsof(state->xeh); i++)
state->xeh[i] = -1;
for (i = 0; i < elementsof(hex) - 1; i++)
state->xeh[hex[i]] = i >= 16 ? (i - 6) : i;
}
p->data = state;
state->codex = p;
return 0;
}
static ssize_t
qp_read(Sfio_t* sp, void* buf, size_t n, Sfdisc_t* disc)
{
register State_t* state = (State_t*)CODEX(disc)->data;
register char* s = (char*)buf;
register char* e = s + n;
register char* x;
register int c;
register int d;
x = 0;
while (s < e)
{
switch (c = GETCHAR(state))
{
case '=':
if ((c = GETCHAR(state)) == '\n')
continue;
if ((d = state->xeh[c]) != EOF && (c = state->xeh[GETCHAR(state)]) != EOF)
{
c |= (d << 4);
x = 0;
break;
}
/*FALLTHROUGH*/
case EOF:
return s - (char*)buf;
case '\n':
if (x)
{
s = x;
x = 0;
}
break;
case ' ':
case '\t':
case '\r':
if (!x)
x = s;
break;
default:
x = 0;
break;
}
*s++ = c;
}
if (x)
while (s > x && state->bp > state->buf)
*--state->bp = *--s;
return s - (char*)buf;
}
static ssize_t
qp_write(Sfio_t* sp, const void* buf, size_t n, Sfdisc_t* disc)
{
register State_t* state = (State_t*)CODEX(disc)->data;
register unsigned char* s;
register unsigned char* e;
register int c;
register int col;
again:
if (state->pp)
{
s = state->prv;
e = state->pp;
state->col = 0;
}
else
{
s = (unsigned char*)buf;
e = s + n;
col = state->col;
}
for (;;)
{
if (s >= e)
{
if (state->pp)
{
state->pp = 0;
state->col = col;
goto again;
}
break;
}
c = *s++;
if (!col++)
{
if (c == 'F')
{
if ((e - s) < 4)
{
s--;
col--;
state->pp = state->prv;
for (c = 0; c < (e - s); ++c)
*state->pp++ = s[c];
break;
}
else if (s[0] == 'r' && s[1] == 'o' && s[2] == 'm' && s[3] == ' ')
goto quote;
}
else if (c == '.')
{
if ((e - s) < 1)
{
s--;
col--;
state->pp = state->prv;
*state->pp++ = c;
break;
}
else if (s[0] == '\r' || s[0] == '\n')
goto quote;
}
}
if (c == '\n')
{
col = 0;
PUTCHAR(state, c);
continue;
}
else if (col >= (LINE - 4))
{
col = 0;
PUTCHAR(state, '=');
PUTCHAR(state, '\n');
}
if (c == ' ' || c == '\t')
{
if ((e - s) < 1)
{
s--;
col--;
state->pp = state->prv;
*state->pp++ = c;
break;
}
else if (s[0] == '\r' || s[0] == '\n')
goto quote;
else
{
if (c == '\t')
col |= 7;
PUTCHAR(state, c);
continue;
}
}
#if CC_NATIVE == CC_ASCII
else if (c >= 0x21 && c <= 0x7e && c != '=')
#else
else if (isprint(c) && !iscntrl(c) && c != '=')
#endif
{
PUTCHAR(state, c);
continue;
}
quote:
col += 2;
PUTCHAR(state, '=');
PUTCHAR(state, hex[(c >> 4) & 0xF]);
PUTCHAR(state, hex[c & 0xF]);
}
state->col = col;
return n;
}
static int
qp_sync(Codex_t* p)
{
return flush((State_t*)p->data, -1);
}
Codexmeth_t codex_qp =
{
"qp",
"quoted printable encoding.",
"[+(version)?codex-qp (AT&T Research) 1998-11-11]"
"[+(author)?Glenn Fowler <gsf@research.att.com>]",
CODEX_DECODE|CODEX_ENCODE|CODEX_UU,
0,
0,
qp_open,
0,
0,
0,
qp_read,
qp_write,
qp_sync,
0,
0,
0,
0,
CODEXNEXT(qp)
};
CODEXLIB(qp)

View file

@ -1,136 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* rot13 decoder/encoder
*/
#include <codex.h>
typedef struct State_s
{
unsigned char rot[256];
unsigned char* buf;
size_t bufsiz;
} State_t;
static const char rot[] = "abcdefghijklmnopqrstuvwxyz";
static const char ROT[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static int
rot13_open(Codex_t* p, char* const args[], Codexnum_t flags)
{
register State_t* state;
register int i;
if (!(state = newof(0, State_t, 1, 0)))
{
if (p->disc->errorf)
(*p->disc->errorf)(NiL, p->disc, 2, "out of space");
return -1;
}
for (i = 0; i < sizeof(state->rot); i++)
state->rot[i] = i;
for (i = 0; i < sizeof(rot); i++)
state->rot[rot[i]] = rot[(i + 13) % 26];
for (i = 0; i < sizeof(ROT); i++)
state->rot[ROT[i]] = ROT[(i + 13) % 26];
p->data = state;
return 0;
}
static int
rot13_close(Codex_t* p)
{
State_t* state = (State_t*)p->data;
if (!state)
return -1;
if (state->buf)
free(state->buf);
free(state);
return 0;
}
static ssize_t
rot13_read(Sfio_t* sp, void* buf, size_t n, Sfdisc_t* disc)
{
register State_t* state = (State_t*)CODEX(disc)->data;
register unsigned char* s;
register unsigned char* e;
ssize_t r;
if ((r = sfrd(sp, buf, n, disc)) > 0)
for (e = (s = (unsigned char*)buf) + r; s < e; s++)
*s = state->rot[*s];
return r;
}
static ssize_t
rot13_write(Sfio_t* sp, const void* buf, size_t n, Sfdisc_t* disc)
{
register State_t* state = (State_t*)CODEX(disc)->data;
register unsigned char* s;
register unsigned char* e;
register unsigned char* b;
if (n > state->bufsiz)
{
state->bufsiz = roundof(n, 1024);
if (!(state->buf = newof(state->buf, unsigned char, state->bufsiz, 0)))
{
if (CODEX(disc)->disc->errorf)
(*CODEX(disc)->disc->errorf)(NiL, CODEX(disc)->disc, 2, "out of space");
return -1;
}
}
for (b = state->buf, e = (s = (unsigned char*)buf) + n; s < e; s++)
*b++ = state->rot[*s];
return sfwr(sp, state->buf, n, disc);
}
Codexmeth_t codex_rot13 =
{
"rot13",
"rot13 self-inverting encoding.",
"[+(version)?codex-rot13 (AT&T Research) 2003-12-11]"
"[+(author)?Glenn Fowler <gsf@research.att.com>]",
CODEX_DECODE|CODEX_ENCODE|CODEX_UU,
0,
0,
rot13_open,
rot13_close,
0,
0,
rot13_read,
rot13_write,
0,
0,
0,
0,
0,
CODEXNEXT(rot13)
};
CODEXLIB(rot13)

View file

@ -1,520 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* uuencode familiy coders
*/
#include <codex.h>
#include <ctype.h>
#define UUIN 3
#define UUOUT 4
#define UUCHUNK 15
#define UU_END (UCHAR_MAX)
#define UU_IGN (UCHAR_MAX-1)
#define UU_PAD (UCHAR_MAX-2)
typedef struct
{
int pad;
int fill;
int length;
const char map[65];
} Data_t;
typedef struct State_s
{
Codex_t* codex;
const Data_t* data;
unsigned char* bb;
unsigned char* bp;
unsigned char* bl;
unsigned char* be;
unsigned char* map;
unsigned char* pb;
unsigned char* pp;
int c1;
int c2;
int nl;
int string;
int text;
unsigned char mapbuf[UCHAR_MAX + 2];
unsigned char buf[SF_BUFSIZE];
unsigned char peek[UUIN];
} State_t;
static const Data_t uu_base64 =
{
'=',
0,
0,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
};
static const Data_t uu_bsd =
{
0,
0156,
1,
"`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
};
static const Data_t uu_posix =
{
0,
0,
1,
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
};
#define GETCHAR(p) ((p)->bp < (p)->be ? (int)*(p)->bp++ : fill(p))
#define PUTCHAR(p,s,e,c) ((s<e) ? (*s++=(c)) : (*p->pp++=(c)))
static int
fill(State_t* state)
{
ssize_t r;
state->bp = state->buf;
if ((r = sfrd(state->codex->sp, state->bp, sizeof(state->buf), &state->codex->sfdisc)) <= 0)
{
state->be = state->bp;
return EOF;
}
state->be = state->bp + r;
return *state->bp++;
}
static int
flush(register State_t* state)
{
uint32_t b;
int c3;
int x;
x = 1;
if (state->c1 >= 0)
{
c3 = state->data->fill;
x++;
if (state->c2 < 0)
{
state->c2 = c3;
x++;
}
b = (state->c1 << 16) | (state->c2 << 8) | c3;
*state->bp++ = state->data->map[b >> 18];
*state->bp++ = state->data->map[(b >> 12) & 077];
*state->bp++ = x == 3 && state->data->pad ? state->data->pad : state->data->map[(b >> 6) & 077];
*state->bp++ = state->data->pad ? state->data->pad : state->data->map[b & 077];
state->c1 = state->c2 = -1;
}
if ((state->bl - state->bp) < UUOUT * UUCHUNK || state->bp > state->buf + !!state->bb)
{
if (state->bb)
*state->bb = state->data->map[((state->bp - state->bb - x) / UUOUT) * UUIN + 1];
if (state->string)
{
if (*(state->bp - 1) == '\n')
state->bp--;
}
else
{
if (*(state->bp - 1) != '\n')
*state->bp++ = '\n';
}
x = state->bp - state->buf;
state->bp = state->buf;
state->bl = state->bp + UUOUT * UUCHUNK;
if (sfwr(state->codex->sp, state->buf, x, &state->codex->sfdisc) != x)
return EOF;
}
return 0;
}
static int
uu_open(Codex_t* p, char* const args[], Codexnum_t flags)
{
register State_t* state;
register char* s;
register char** a;
unsigned char* m;
unsigned char* q;
const Data_t* data;
int c;
int n;
int string;
int text;
data = &uu_posix;
string = text = 0;
a = (char**)args + 1;
while (s = *++a)
if (streq(s, "base64") || streq(s, "mime"))
data = &uu_base64;
else if (streq(s, "bsd") || streq(s, "ucb"))
data = &uu_bsd;
else if (streq(s, "posix"))
data = &uu_posix;
else if (streq(s, "string"))
{
if (data != &uu_base64)
{
if (p->disc->errorf)
(*p->disc->errorf)(NiL, p->disc, 2, "%s: %s: option valid for base64/mime only", p->meth->name, s);
return -1;
}
string = 1;
}
else if (streq(s, "text"))
text = 1;
else
{
if (p->disc->errorf)
(*p->disc->errorf)(NiL, p->disc, 2, "%s: %s: unknown option", p->meth->name, s);
return -1;
}
if (!(state = newof(0, State_t, 1, 0)))
{
if (p->disc->errorf)
(*p->disc->errorf)(NiL, p->disc, 2, "out of space");
return -1;
}
state->data = data;
state->string = string;
state->text = text;
if (p->flags & CODEX_DECODE)
{
n = data->length ? 0 : UU_IGN;
q = state->mapbuf;
memset(q, n, sizeof(state->mapbuf));
state->map = ++q;
q[EOF] = UU_END;
if (n)
q[data->pad] = UU_PAD;
for (m = (unsigned char*)data->map; c = *m; m++)
q[c] = m - (unsigned char*)data->map;
}
p->data = state;
state->codex = p;
return 0;
}
static int
uu_init(Codex_t* p)
{
register State_t* state = (State_t*)p->data;
int n;
state->bp = state->buf;
if (p->flags & CODEX_ENCODE)
{
n = UUOUT * UUCHUNK + state->data->length + 1;
state->be = state->bp + (sizeof(state->buf) / n) * n;
if (state->data->length)
{
state->bb = state->bp;
*state->bp++ = state->data->map[UUIN * UUCHUNK];
}
state->bl = state->bp + UUOUT * UUCHUNK;
state->c1 = state->c2 = -1;
}
else
{
state->be = state->bp;
state->pb = state->pp = state->peek;
if (state->data->length)
state->nl = -1;
state->c1 = state->c2 = -1;
}
return 0;
}
static ssize_t
uu_read(Sfio_t* sp, void* buf, size_t n, Sfdisc_t* disc)
{
register State_t* state = (State_t*)CODEX(disc)->data;
register char* s = (char*)buf;
register char* e = s + n;
register uint32_t b;
register int c;
register int x;
if (state->pb < state->pp)
{
while (s < e && state->pb < state->pp)
*s++ = *state->pb++;
if (state->pb == state->pp)
state->pb = state->pp = state->peek;
}
if (state->data->length)
while (s < e)
{
switch (c = GETCHAR(state))
{
case EOF:
goto done;
case '\n':
state->nl = -1;
continue;
}
if (state->nl < 0)
state->nl = state->map[c];
else if (state->nl > 0)
{
b = state->map[c];
if ((c = GETCHAR(state)) == EOF)
c = 0;
else
c = state->map[c];
b = (b << 6) | c;
if ((c = GETCHAR(state)) == EOF)
c = 0;
else
c = state->map[c];
b = (b << 6) | c;
if ((c = GETCHAR(state)) == EOF)
c = 0;
else
c = state->map[c];
b = (b << 6) | c;
if (state->text)
{
if ((c = (b >> 16) & 0xFF) != '\r')
PUTCHAR(state, s, e, c);
if ((c = (b >> 8) & 0xFF) != '\r')
PUTCHAR(state, s, e, c);
if ((c = b & 0xFF) != '\r')
PUTCHAR(state, s, e, c);
}
else
{
PUTCHAR(state, s, e, (b >> 16));
PUTCHAR(state, s, e, (b >> 8));
PUTCHAR(state, s, e, b);
}
if ((state->nl -= 3) < 0)
while (state->nl++ < 0)
s--;
}
}
else
while (s < e)
{
while ((c = state->map[GETCHAR(state)]) >= 64)
if (c != UU_IGN)
goto done;
b = c;
while ((c = state->map[GETCHAR(state)]) >= 64)
if (c != UU_IGN)
{
if (state->codex->disc->errorf)
(*state->codex->disc->errorf)(NiL, state->codex->disc, 1, "%c: extra input character ignored", c);
goto done;
}
b = (b << 6) | c;
while ((c = state->map[GETCHAR(state)]) >= 64)
if (c != UU_IGN)
{
if (state->text)
{
if ((x = (b >> 4) & 0xFF) != '\r')
PUTCHAR(state, s, e, x);
}
else
PUTCHAR(state, s, e, (b >> 4));
goto done;
}
b = (b << 6) | c;
while ((c = state->map[GETCHAR(state)]) >= 64)
if (c != UU_IGN)
{
if (state->text)
{
if ((x = (b >> 10) & 0xFF) != '\r')
PUTCHAR(state, s, e, x);
if ((x = (b >> 2) & 0xFF) != '\r')
PUTCHAR(state, s, e, x);
}
else
{
PUTCHAR(state, s, e, (b >> 10));
PUTCHAR(state, s, e, (b >> 2));
}
goto done;
}
b = (b << 6) | c;
if (state->text)
{
if ((x = (b >> 16) & 0xFF) != '\r')
PUTCHAR(state, s, e, x);
if ((x = (b >> 8) & 0xFF) != '\r')
PUTCHAR(state, s, e, x);
if ((x = b & 0xFF) != '\r')
PUTCHAR(state, s, e, x);
}
else
{
PUTCHAR(state, s, e, (b >> 16));
PUTCHAR(state, s, e, (b >> 8));
PUTCHAR(state, s, e, b);
}
}
done:
return s - (char*)buf;
}
static ssize_t
uu_write(Sfio_t* sp, const void* buf, size_t n, Sfdisc_t* disc)
{
register State_t* state = (State_t*)CODEX(disc)->data;
register unsigned char* s;
register unsigned char* e;
register uint32_t b;
register int c1;
register int c2;
register int c3;
s = (unsigned char*)buf;
e = s + n;
if ((c1 = state->c1) >= 0)
{
state->c1 = -1;
if ((c2 = state->c2) >= 0)
{
state->c2 = -1;
goto get_3;
}
goto get_2;
}
while (s < e)
{
do
{
if (state->nl)
{
state->nl = 0;
c1 = '\n';
goto get_2;
}
if (s >= e)
break;
c1 = *s++;
if (state->text && c1 == '\n')
{
c1 = '\r';
c2 = '\n';
goto get_3;
}
get_2:
if (s >= e)
{
state->c1 = c1;
return n;
}
c2 = *s++;
if (state->text && c2 == '\n')
{
c2 = '\r';
c3 = '\n';
goto put_123;
}
get_3:
if (s >= e)
{
state->c1 = c1;
state->c2 = c2;
return n;
}
c3 = *s++;
if (state->text && c3 == '\n')
{
state->nl = 1;
c3 = '\r';
}
put_123:
b = (c1 << 16) | (c2 << 8) | c3;
*state->bp++ = state->data->map[b >> 18];
*state->bp++ = state->data->map[(b >> 12) & 077];
*state->bp++ = state->data->map[(b >> 6) & 077];
*state->bp++ = state->data->map[b & 077];
} while (state->bp < state->bl);
if (!state->string)
*state->bp++ = '\n';
if (state->bp >= state->be)
{
if (sfwr(sp, state->buf, state->bp - state->buf, disc) != (state->bp - state->buf))
return -1;
state->bp = state->buf;
}
if (state->bb)
{
state->bb = state->bp;
*state->bp++ = state->data->map[UUIN * UUCHUNK];
}
state->bl = state->bp + UUOUT * UUCHUNK;
}
return n;
}
static int
uu_sync(Codex_t* p)
{
return (p->flags & CODEX_ENCODE) ? flush((State_t*)p->data) : 0;
}
Codexmeth_t codex_uu =
{
"uu",
"uuencode printable encoding.",
"[+posix?Posix \buuencode\b(1). This is the default.]"
"[+base64|mime?MIME base64 encoding.]"
"[+bsd|ucb?BSD \buuencode\b(1).]"
"[+string?Encode into a string with no separators (base64 only).]"
"[+text?Encode \\n => \\r\\n, decode \\r\\n => \\n.]"
"[+(version)?codex-uu (AT&T Research) 2010-01-15]"
"[+(author)?Glenn Fowler <gsf@research.att.com>]",
CODEX_DECODE|CODEX_ENCODE|CODEX_UU,
0,
0,
uu_open,
0,
uu_init,
0,
uu_read,
uu_write,
uu_sync,
0,
0,
0,
0,
CODEXNEXT(uu)
};
CODEXLIB(uu)

File diff suppressed because it is too large Load diff

View file

@ -1,174 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* codex public interface
*/
#ifndef _CODEX_H
#define _CODEX_H 1
#include <ast.h>
#include <error.h>
#define CODEX_VERSION 20090704L
#define CODEX_PLUGIN_VERSION AST_PLUGIN_VERSION(CODEX_VERSION)
#define CODEX_DECODE 0x0001 /* decode supported */
#define CODEX_ENCODE 0x0002 /* encode supported */
#define CODEX_RETAIN 0x0010 /* initf-donef retain state */
#define CODEX_INVERT 0x0020 /* invert composition */
#define CODEX_TRACE 0x0040 /* enable trace */
#define CODEX_VERBOSE 0x0080 /* enable verbose trace */
#define CODEX_COMPRESS 0x0100 /* compression */
#define CODEX_CRYPT 0x0200 /* encryption */
#define CODEX_ICONV 0x0400 /* character code translation */
#define CODEX_SUM 0x0800 /* checksum */
#define CODEX_UU 0x1000 /* uuencode (ISO text) */
#define CODEX_CACHED 0x10000000L /* cached entry */
#define CODEX_SERIAL 0x20000000L /* serial number assigned */
#define CODEX_FLUSH 0x40000000L /* flush-only sync */
#define CODEX_ACTIVE 0x80000000L /* active cache entry */
#define CODEX_IDENT 1024 /* max ident buffer size */
#define CODEX_NAME 256 /* max coder name w/args */
#define CODEX_ARGS 32 /* max coder args in name */
#define CODEX(d) ((Codex_t*)(d))
typedef uint32_t Codexnum_t;
struct Codex_s; typedef struct Codex_s Codex_t;
struct Codexdata_s; typedef struct Codexdata_s Codexdata_t;
struct Codexdisc_s; typedef struct Codexdisc_s Codexdisc_t;
struct Codexmeth_s; typedef struct Codexmeth_s Codexmeth_t;
typedef Codexmeth_t* (*Codexlib_f)(const char*);
struct Codex_s /* coder public state */
{
Sfdisc_t sfdisc; /* coder sfio discipline */
Sfio_t* sp; /* data base stream */
Sfio_t* dp; /* optional data delta stream */
Sfoff_t size; /* expected size if != -1 */
Codexdisc_t* disc; /* coder discipline */
Codexmeth_t* meth; /* coder method */
Codexnum_t flags; /* CODEX_* flags */
Codexnum_t index; /* per-process index */
int serial; /* codex() serial number */
void* data; /* coder private state */
Sfio_t* op; /* original stream */
};
struct Codexdata_s /* codexdata() info */
{
Codexnum_t size; /* value size */
Codexnum_t num; /* value if buf!=0 */
void* buf; /* size byte value */
};
struct Codexdisc_s /* coder discipline */
{
Codexnum_t version; /* CODEX_VERSION */
Error_f errorf; /* error message function */
ssize_t (*passf)(void*, size_t, Codexdisc_t*, Codexmeth_t*);
const char* passphrase; /* passphrase */
Sfio_t* identify; /* decode method string if != 0 */
};
struct Codexmeth_s /* coder method */
{
const char* name; /* coder name */
const char* description; /* coder description */
const char* options; /* static optget() options */
Codexnum_t flags; /* CODEX_* flags */
int (*optionsf)(Codexmeth_t*, Sfio_t*);
int (*identf)(Codexmeth_t*, const void*, size_t, char*, size_t);
int (*openf)(Codex_t*, char* const[], Codexnum_t);
int (*closef)(Codex_t*);
int (*initf)(Codex_t*);
int (*donef)(Codex_t*);
ssize_t (*readf)(Sfio_t*, void*, size_t, Sfdisc_t*);
ssize_t (*writef)(Sfio_t*, const void*, size_t, Sfdisc_t*);
int (*syncf)(Codex_t*);
Sfoff_t (*seekf)(Codex_t*, Sfoff_t, int);
int (*dataf)(Codex_t*, Codexdata_t*);
void* vcmeth; /* vcodex(3) method */
void* data; /* coder private data */
Codexmeth_t* next; /* next in list of all coders */
};
#if _BLD_codex && !defined(main)
#include <codexlib.h>
#define CODEXLIB(m)
#define CODEXNEXT(m) codex_##m##_next
#else
#ifdef __STDC__
#define CODEXLIB(m) extern Codexmeth_t* codex_lib(const char* name) { return &codex_##m; } unsigned long plugin_version(void) { return CODEX_PLUGIN_VERSION; }
#else
#define CODEXLIB(m) extern Codexmeth_t* codex_lib(name) char* name; { return &codex_##m; } unsigned long plugin_version() { return CODEX_PLUGIN_VERSION; }
#endif
#define CODEXNEXT(m) 0
#if defined(__EXPORT__)
#define extern __EXPORT__
#endif
extern Codexmeth_t* codex_lib(const char*);
#undef extern
#endif
#define codexinit(d,e) (memset(d,0,sizeof(*(d))),(d)->version=CODEX_VERSION,(d)->errorf=(Error_f)(e))
#if _BLD_codex && defined(__EXPORT__)
#define extern __EXPORT__
#endif
extern int codex(Sfio_t*, Sfio_t*, const char*, Codexnum_t, Codexdisc_t*, Codexmeth_t*);
extern int codexpop(Sfio_t*, Sfio_t*, int);
extern int codexcmp(const char*, const char*);
extern int codexdata(Sfio_t*, Codexdata_t*);
extern ssize_t codexgetpass(const char*, void*, size_t);
extern Codexmeth_t* codexid(const void*, size_t, char*, size_t);
extern Codexmeth_t* codexlist(Codexmeth_t*);
extern Codexmeth_t* codexmeth(const char*);
extern int codexadd(const char*, Codexmeth_t*);
extern Sfio_t* codexnull(void);
extern ssize_t codexpass(void*, size_t, Codexdisc_t*, Codexmeth_t*);
extern int codexsize(Sfio_t*, Sfoff_t);
#undef extern
#endif

View file

@ -1,38 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* add new codex method
*/
#include <codex.h>
int
codexadd(const char* name, Codexmeth_t* meth)
{
if (meth->next)
return -1;
meth->next = codexstate.first;
codexstate.first = meth;
return 0;
}

View file

@ -1,54 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* codex method name comparison
* strcmp() semantics
*/
#include <codex.h>
int
codexcmp(register const char* s, register const char* t)
{
for (;;)
{
if (!*s)
{
if (!*t || *t == '-' || *t == '+' || *t == '<' || *t == '>' || *t == '|' || *t == '^')
return 0;
break;
}
if (!*t)
{
if (*s == '-' || *s == '+' || *s == '<' || *s == '>' || *s == '|' || *s == '^')
return 0;
break;
}
if (*s != *t)
break;
s++;
t++;
}
return *((unsigned char*)s) - *((unsigned char*)t);
}

View file

@ -1,34 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* get method specific data
*/
#include <codex.h>
int
codexdata(Sfio_t* sp, Codexdata_t* data)
{
return sfraise(sp, CODEX_DATA, data);
}

View file

@ -1,74 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* prompt for password and return it in buf
* return < 0 : error
* return >= n : n-1 in buf, nul terminated
*/
#include <codex.h>
#include <sig.h>
#include <ast_tty.h>
ssize_t
codexgetpass(const char* prompt, void* buf, size_t n)
{
char* s;
long flags;
ssize_t r;
Sfio_t* rp;
Sfio_t* wp;
Sig_handler_t sigint;
struct termios tty;
if (rp = sfopen(NiL, "/dev/tty", "r+"))
wp = rp;
else
{
rp = sfstdin;
wp = sfstderr;
}
sigint = signal(SIGINT, SIG_IGN);
tcgetattr(sffileno(rp), &tty);
flags = tty.c_lflag;
tty.c_lflag &= ~(ECHO|ECHONL);
tcsetattr(sffileno(rp), TCSANOW, &tty);
tty.c_lflag = flags;
if (prompt)
{
sfprintf(wp, "%s", prompt);
sfsync(wp);
}
if (s = sfgetr(rp, '\n', 1))
r = strncopy((char*)buf, s, n) - (char*)buf;
else
r = -1;
sfprintf(wp, "\n");
sfsync(wp);
tcsetattr(sffileno(rp), TCSANOW, &tty);
signal(SIGINT, sigint);
if (rp == wp)
sfclose(rp);
return r;
}

View file

@ -1,40 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* identify encoding given first block of encoded data
* not all encodings are expected to self-identify
*/
#include <codex.h>
Codexmeth_t*
codexid(const void* head, size_t headsize, char* name, size_t namesize)
{
register Codexmeth_t* meth;
for (meth = codexlist(NiL); meth; meth = codexlist(meth))
if (meth->identf && (*meth->identf)(meth, head, headsize, name, namesize))
return meth;
return 0;
}

View file

@ -1,83 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* codex private interface
* included by <codex.h>
*/
#ifndef _CODEXLIB_H
#define _CODEXLIB_H
#include <debug.h>
#ifndef SFDCEVENT
#define SFDCEVENT(a,b,n) ((((a)-'A'+1)<<11)^(((b)-'A'+1)<<6)^(n))
#endif
#define CODEX_DATA SFDCEVENT('C','X','d') /* get data */
#define CODEX_GETPOS SFDCEVENT('C','X','g') /* get position */
#define CODEX_SETPOS SFDCEVENT('C','X','s') /* set position */
#define CODEX_SIZE SFDCEVENT('C','X','z') /* set size */
typedef struct Codexcache_s
{
Codex_t* code;
Codexnum_t flags;
Codexnum_t cached;
char name[CODEX_NAME];
} Codexcache_t;
typedef struct Codexstate_s
{
const char* id;
Codexmeth_t* first;
Codexdisc_t disc;
Codex_t error;
Codex_t* last;
char* trace;
char* verbose;
Codexnum_t index;
int serial;
unsigned int initialized;
unsigned int scanned;
unsigned int cached;
Codexcache_t cache[16];
} Codexstate_t;
#define CODEXERROR (&codexstate.error)
#define codex_first (&codex_uu)
#define codex_uu_next (&codex_qp)
#define codex_qp_next (&codex_rot13)
#define codex_rot13_next (&codex_iconv)
#define codex_iconv_next 0
extern Codexmeth_t codex_iconv;
extern Codexmeth_t codex_qp;
extern Codexmeth_t codex_rot13;
extern Codexmeth_t codex_uu;
extern Codexstate_t codexstate;
#endif

View file

@ -1,65 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* return the next codex method
* call with meth==0 to get the first method
* plugins are included in the list
*/
#include <codex.h>
#include <dlldefs.h>
Codexmeth_t*
codexlist(Codexmeth_t* meth)
{
register Codexmeth_t* lp;
Codexmeth_t* np;
Dllscan_t* dls;
Dllent_t* dle;
void* dll;
Codexlib_f lib;
if (!meth)
return codexstate.first;
if (!meth->next && !codexstate.scanned)
{
codexstate.scanned = 1;
lp = meth;
if (dls = dllsopen(codexstate.id, NiL, NiL))
{
while (dle = dllsread(dls))
if (dll = dlopen(dle->path, RTLD_LAZY))
{
if ((lib = (Codexlib_f)dlllook(dll, "codex_lib")) && (np = (*lib)(dle->name)))
for (lp = lp->next = np; lp->next; lp = lp->next);
else
dlclose(dll);
}
else
message((-1, "%s: %s", dle->path, dlerror()));
dllsclose(dls);
}
}
return meth->next;
}

View file

@ -1,75 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* return the codex method for name
*/
#include <codex.h>
#include <dlldefs.h>
Codexmeth_t*
codexmeth(const char* name)
{
register Codexmeth_t* meth;
register const char* s;
register const char* t;
Codexmeth_t* last;
void* dll;
int plugin;
Codexlib_f lib;
char tmp[CODEX_NAME];
if (!name)
return CODEXERROR->meth;
plugin = 0;
meth = codexstate.first;
while (meth)
{
if (!codexcmp(name, meth->name))
return meth;
last = meth;
if (!(meth = meth->next) && !plugin)
{
plugin = 1;
for (s = name, t = 0; *s && *s != '+'; s++)
if (*s == '-')
{
if (t)
break;
t = s;
}
do
{
sfsprintf(tmp, sizeof(tmp), "%-.*s", s - name, name);
if (dll = dllplug("codex", tmp, NiL, RTLD_LAZY, NiL, 0))
{
if ((lib = (Codexlib_f)dlllook(dll, "codex_lib")) && (meth = (*lib)(name)))
last->next = meth;
break;
}
} while (s != t && (s = t));
}
}
return meth;
}

View file

@ -1,53 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* return null write stream for pure codexdata()
*/
#include <sfio_t.h>
#include <codex.h>
static ssize_t
nullread(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc)
{
return 0;
}
static ssize_t
nullwrite(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc)
{
return n;
}
static Sfdisc_t nulldisc = { nullread, nullwrite };
static const char nullbuf[1];
static Sfio_t null = SFNEW(nullbuf, 0, 0, SF_WRITE, &nulldisc, 0);
Sfio_t*
codexnull(void)
{
return &null;
}

View file

@ -1,43 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* return password buf
* return < 0 : error
* return >= n : n-1 in buf
*/
#include <codex.h>
ssize_t
codexpass(void* buf, size_t n, Codexdisc_t* disc, Codexmeth_t* meth)
{
char prompt[2 * CODEX_NAME];
if (disc->passphrase)
return strncopy((char*)buf, disc->passphrase, n) - (char*)buf;
if (disc->passf)
return (*disc->passf)(buf, n, disc, meth);
sfsprintf(prompt, sizeof(prompt), "Enter %s passphrase: ", meth->name);
return codexgetpass(prompt, buf, n);
}

View file

@ -1,34 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* set expected output size
*/
#include <codex.h>
int
codexsize(Sfio_t* sp, Sfoff_t size)
{
return sfraise(sp, CODEX_SIZE, &size);
}

View file

@ -1,80 +0,0 @@
/*
* connect stream library
*/
:PACKAGE: ast
LICENSE = since=1990,author=gsf
ID = cs
DEBUG == 1
CCFLAGS = $(CC.OPTIMIZE) $(CC.SUFFIX.DYNAMIC:@?$(CC.DLL)??)
TRUST == "$(INSTALLROOT):$(OPTDIRS:/:/ /G:C%$%/$(.PACKAGE.:O=1)%:/ /:/G):$(USRDIRS)"
HEADERS = cs.h css.h msg.h ast_cs.h cs_lib.h
$(ID) 3.0 :LIBRARY: RELEASE cs.3 \
$(HEADERS) cslib.h csslib.h \
csalloc.c csfree.c \
csaddr.c csattr.c csauth.c csbind.c csclient.c cscontrol.c \
csdaemon.c csdata.c csfrom.c csfull.c csinfo.c cslocal.c \
csname.c csnote.c csntoa.c csopen.c cspath.c cspeek.c \
csping.c cspipe.c cspoll.c csport.c csread.c csrecv.c \
cssend.c css.c csserve.c csstat.c csto.c csvar.c cswrite.c \
msglib.h msgblast.c msgbuf.c msggetmask.c msgindex.c \
msginfo.c msglist.c msgname.c msgread.c msgrecv.c msgsend.c \
msgsetmask.c msguser.c \
-lin -lipc -lnetcompat \
$(CC.HOSTTYPE:N=$(-mam:N=static*:?UNKNOWN?sgi.mips*?):??-lsocket -linet -lnsl -ldl?)
$(HEADERS:N=*_*.h) :COPY: FEATURE/$$(<:B:/.*_//)
$(INCLUDEDIR) :INSTALLPROTO: $(HEADERS)
$(LIBDIR)/$(ID) :INSTALLDIR: genlocal genshare
$(SHAREDIR)/lib/$(ID) :INSTALLDIR: local.ast genlocal genshare
$(SHAREDIR)/lib/$(ID)/tcp :INSTALLDIR: mode=+rwxt
$(SHAREDIR)/lib/$(ID)/udp :INSTALLDIR: mode=+rwxt
$(LIBDIR)/make :INSTALLDIR: SERVICE.mk
/*
* share and local will most likely require human intervention
* so we generate minimal files with obnoxious warnings
*/
genlocal :: genlocal.sh
genshare :: genshare.sh
share : genshare FEATURE/lib $(SHAREDIR)
if test ! -f $(<)
then {
rsh=`$(SED) -e '/^#define CS_REMOTE_SHELL/!d' -e 's/.*"\(.*\)".*/\1/' $(*:O=2)`
echo "#!!! 1 to update this file: $INSTALLROOT/lib/$(ID)/$(*:O=1) -d $(*:O=3) -r $rsh > $(<) !!!"
} > $(<)
fi
"local" : genlocal FEATURE/lib share
if test ! -f $(<)
then {
rsh=`$(SED) -e '/^#define CS_REMOTE_SHELL/!d' -e 's/.*"\(.*\)".*/\1/' $(*:O=2)`
echo "#!!! 1 to update this file: $INSTALLROOT/lib/$(ID)/$(*:O=1) -r $rsh > $(<) !!!"
} > $(<)
fi
$(LIBDIR)/$(ID) :INSTALLDIR: share
if test ! -f $(<)
then $(CP) $(*) $(<)
fi
$(SHAREDIR)/lib/$(ID) :INSTALLDIR: local
if test ! -f $(<)
then $(CP) $(*) $(<)
fi

View file

@ -1,901 +0,0 @@
info mam static 00000 1994-07-17 make (AT&T Research) 5.7 2012-06-20
setv INSTALLROOT ../../..
setv PACKAGE_ast_INCLUDE ${INSTALLROOT}/include/ast
setv PACKAGE_ast_LIB ${INSTALLROOT}/lib
setv PACKAGEROOT ../../../../..
setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS}
setv ARFLAGS rc
setv AS as
setv ASFLAGS
setv CC cc
setv mam_cc_FLAGS ${mam_cc_DLL}
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
setv COTEMP $$
setv CPIO cpio
setv CPIOFLAGS
setv CPP "${CC} -E"
setv F77 f77
setv HOSTCC ${CC}
setv IGNORE
setv LD ld
setv LDFLAGS
setv LEX lex
setv LEXFLAGS
setv LPR lpr
setv LPRFLAGS
setv M4FLAGS
setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
setv SHELL /bin/sh
setv SILENT
setv TAR tar
setv YACC yacc
setv YACCFLAGS -d
make ${PACKAGEROOT}/lib/package/ast.lic
done ${PACKAGEROOT}/lib/package/ast.lic
make install
make cs
make libcs.a archive
make cs.req
exec - set -
exec - echo 'int main(){return 0;}' > 1.${COTEMP}.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -c 1.${COTEMP}.c &&
exec - x=`${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l'*' 2>&1 | sed -e 's/[][()+@?]/#/g' || :` &&
exec - {
exec - case "" in
exec - *?) echo " " ;;
exec - esac
exec - for i in cs in ipc netcompat socket inet nsl dl ast
exec - do case $i in
exec - "cs"|cs)
exec - ;;
exec - *) if test -f ${INSTALLROOT}/lib/lib/$i
exec - then y=`cat ${INSTALLROOT}/lib/lib/$i`
exec - case $y in
exec - *-?*) echo "" $y ;;
exec - esac
exec - continue
exec - elif test ! -f ${INSTALLROOT}/lib/lib$i.a
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) continue ;;
exec - esac
exec - ;;
exec - esac
exec - fi
exec - ;;
exec - esac
exec - echo " -l$i"
exec - done
exec - } > cs.req
exec - rm -f 1.${COTEMP}.*
done cs.req generated
make csalloc.o
make csalloc.c
make cslib.h implicit
make ${PACKAGE_ast_INCLUDE}/endian.h implicit
make ${PACKAGE_ast_INCLUDE}/bytesex.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_map.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_common.h dontcare
done ${PACKAGE_ast_INCLUDE}/bytesex.h dontcare
done ${PACKAGE_ast_INCLUDE}/endian.h dontcare
make stropts.h implicit
done stropts.h dontcare virtual
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
make cs_lib.h implicit
make FEATURE/lib
meta FEATURE/lib features/%>FEATURE/% features/lib lib
make features/lib
done features/lib
bind -ldl dontcare
bind -last
exec - iffe -v -c '${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ' ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdl} ${mam_libast} : run features/lib
done FEATURE/lib generated
exec - cmp 2>/dev/null -s FEATURE/lib cs_lib.h || { rm -f cs_lib.h; silent test -d . || mkdir .; cp FEATURE/lib cs_lib.h; }
done cs_lib.h dontcare generated
make ${PACKAGE_ast_INCLUDE}/ast_tty.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_tty.h dontcare
make ${PACKAGE_ast_INCLUDE}/tok.h implicit
make ${PACKAGE_ast_INCLUDE}/ast.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_api.h dontcare
make ${PACKAGE_ast_INCLUDE}/vmalloc.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
make ${PACKAGE_ast_INCLUDE}/regex.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_api.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
make ${PACKAGE_ast_INCLUDE}/wctype.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_wctype.h implicit
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
make ${PACKAGE_ast_INCLUDE}/wchar.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h implicit
done ${PACKAGE_ast_INCLUDE}/wchar.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_wctype.h dontcare
done ${PACKAGE_ast_INCLUDE}/wctype.h dontcare
make ${PACKAGE_ast_INCLUDE}/stdio.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_stdio.h implicit
make ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio_s.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_stdio.h dontcare
done ${PACKAGE_ast_INCLUDE}/stdio.h dontcare
prev ${PACKAGE_ast_INCLUDE}/stdio.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_wchar.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
make ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/prototyped.h dontcare
done ${PACKAGE_ast_INCLUDE}/regex.h dontcare
make ${PACKAGE_ast_INCLUDE}/getopt.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_getopt.h dontcare
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/getopt.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_map.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_botch.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_botch.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_limits.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_limits.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_fcntl.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_fs.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_fs.h dontcare
done ${PACKAGE_ast_INCLUDE}/ast_fcntl.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_getopt.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_sys.h implicit
prev ${PACKAGE_ast_INCLUDE}/getopt.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_sys.h dontcare
make ${PACKAGE_ast_INCLUDE}/ast_lib.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_lib.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_std.h dontcare
done ${PACKAGE_ast_INCLUDE}/vmalloc.h dontcare
make ${PACKAGE_ast_INCLUDE}/sfio.h implicit
prev ${PACKAGE_ast_INCLUDE}/sfio_s.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/sfio.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast.h dontcare
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/tok.h dontcare
make ${PACKAGE_ast_INCLUDE}/sig.h implicit
done ${PACKAGE_ast_INCLUDE}/sig.h dontcare
make ${PACKAGE_ast_INCLUDE}/debug.h implicit
make ${PACKAGE_ast_INCLUDE}/error.h implicit
make ${PACKAGE_ast_INCLUDE}/option.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/option.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/error.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/debug.h dontcare
make cs.h implicit
make ${PACKAGE_ast_INCLUDE}/times.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_time.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_time.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/times.h dontcare
make ${PACKAGE_ast_INCLUDE}/ls.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_mode.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_mode.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_fs.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ls.h dontcare
make ${PACKAGE_ast_INCLUDE}/hashpart.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/hashpart.h dontcare
make ast_cs.h implicit
make FEATURE/cs
meta FEATURE/cs features/%.c>FEATURE/% features/cs.c cs
make features/cs.c
prev FEATURE/lib implicit
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
done features/cs.c
exec - iffe -v -c '${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast ${LDFLAGS} ' ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdl} ${mam_libast} : run features/cs.c
done FEATURE/cs generated
exec - cmp 2>/dev/null -s FEATURE/cs ast_cs.h || { rm -f ast_cs.h; silent test -d . || mkdir .; cp FEATURE/cs ast_cs.h; }
done ast_cs.h dontcare generated
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
done cs.h dontcare
done cslib.h
done csalloc.c
meta csalloc.o %.c>%.o csalloc.c csalloc
prev csalloc.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csalloc.c
done csalloc.o generated
make csfree.o
make csfree.c
prev cslib.h implicit
done csfree.c
meta csfree.o %.c>%.o csfree.c csfree
prev csfree.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csfree.c
done csfree.o generated
make csaddr.o
make csaddr.c
prev cslib.h implicit
done csaddr.c
meta csaddr.o %.c>%.o csaddr.c csaddr
prev csaddr.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csaddr.c
done csaddr.o generated
make csattr.o
make csattr.c
make ${PACKAGE_ast_INCLUDE}/hash.h implicit
prev ${PACKAGE_ast_INCLUDE}/hashpart.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/hash.h
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
prev cslib.h implicit
done csattr.c
meta csattr.o %.c>%.o csattr.c csattr
prev csattr.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csattr.c
done csattr.o generated
make csauth.o
make csauth.c
prev ${PACKAGE_ast_INCLUDE}/error.h implicit
prev cslib.h implicit
done csauth.c
meta csauth.o %.c>%.o csauth.c csauth
prev csauth.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csauth.c
done csauth.o generated
make csbind.o
make csbind.c
prev cslib.h implicit
done csbind.c
meta csbind.o %.c>%.o csbind.c csbind
prev csbind.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csbind.c
done csbind.o generated
make csclient.o
make csclient.c
make FEATURE/termios implicit
meta FEATURE/termios features/%>FEATURE/% features/termios termios
make features/termios
done features/termios
exec - iffe -v -c '${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ' ref ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libdl} ${mam_libast} : run features/termios
done FEATURE/termios generated
prev cslib.h implicit
done csclient.c
meta csclient.o %.c>%.o csclient.c csclient
prev csclient.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csclient.c
done csclient.o generated
make cscontrol.o
make cscontrol.c
prev cslib.h implicit
done cscontrol.c
meta cscontrol.o %.c>%.o cscontrol.c cscontrol
prev cscontrol.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c cscontrol.c
done cscontrol.o generated
make csdaemon.o
make csdaemon.c
prev ${PACKAGE_ast_INCLUDE}/sig.h implicit
prev cslib.h implicit
done csdaemon.c
meta csdaemon.o %.c>%.o csdaemon.c csdaemon
prev csdaemon.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csdaemon.c
done csdaemon.o generated
make csdata.o
make csdata.c
prev cslib.h implicit
done csdata.c
meta csdata.o %.c>%.o csdata.c csdata
prev csdata.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csdata.c
done csdata.o generated
make csfrom.o
make csfrom.c
prev cslib.h implicit
done csfrom.c
meta csfrom.o %.c>%.o csfrom.c csfrom
prev csfrom.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csfrom.c
done csfrom.o generated
make csfull.o
make csfull.c
prev cslib.h implicit
done csfull.c
meta csfull.o %.c>%.o csfull.c csfull
prev csfull.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csfull.c
done csfull.o generated
make csinfo.o
make csinfo.c
prev cslib.h implicit
done csinfo.c
meta csinfo.o %.c>%.o csinfo.c csinfo
prev csinfo.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csinfo.c
done csinfo.o generated
make cslocal.o
make cslocal.c
make ${PACKAGE_ast_INCLUDE}/wait.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_wait.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_wait.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/wait.h
prev cslib.h implicit
done cslocal.c
meta cslocal.o %.c>%.o cslocal.c cslocal
prev cslocal.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c cslocal.c
done cslocal.o generated
make csname.o
make csname.c
prev cslib.h implicit
done csname.c
meta csname.o %.c>%.o csname.c csname
prev csname.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csname.c
done csname.o generated
make csnote.o
make csnote.c
prev cslib.h implicit
done csnote.c
meta csnote.o %.c>%.o csnote.c csnote
prev csnote.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csnote.c
done csnote.o generated
make csntoa.o
make csntoa.c
prev cslib.h implicit
done csntoa.c
meta csntoa.o %.c>%.o csntoa.c csntoa
prev csntoa.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csntoa.c
done csntoa.o generated
make csopen.o
make csopen.c
make ${PACKAGE_ast_INCLUDE}/hashkey.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/hashkey.h
make ${PACKAGE_ast_INCLUDE}/proc.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/proc.h
prev ${PACKAGE_ast_INCLUDE}/error.h implicit
prev cslib.h implicit
done csopen.c
meta csopen.o %.c>%.o csopen.c csopen
prev csopen.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csopen.c
done csopen.o generated
make cspath.o
make cspath.c
make ${PACKAGE_ast_INCLUDE}/ast_dir.h implicit
make ${PACKAGE_ast_INCLUDE}/dirent.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_dirent.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_std.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_dirent.h dontcare
done ${PACKAGE_ast_INCLUDE}/dirent.h dontcare
make dirlib.h implicit
done dirlib.h dontcare virtual
prev ${PACKAGE_ast_INCLUDE}/ast_lib.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_dir.h
prev cslib.h implicit
done cspath.c
meta cspath.o %.c>%.o cspath.c cspath
prev cspath.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c cspath.c
done cspath.o generated
make cspeek.o
make cspeek.c
prev stropts.h implicit
prev cslib.h implicit
done cspeek.c
meta cspeek.o %.c>%.o cspeek.c cspeek
prev cspeek.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c cspeek.c
done cspeek.o generated
make csping.o
make csping.c
prev cslib.h implicit
done csping.c
meta csping.o %.c>%.o csping.c csping
prev csping.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csping.c
done csping.o generated
make cspipe.o
make cspipe.c
prev cslib.h implicit
done cspipe.c
meta cspipe.o %.c>%.o cspipe.c cspipe
prev cspipe.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c cspipe.c
done cspipe.o generated
make cspoll.o
make cspoll.c
prev cslib.h implicit
done cspoll.c
meta cspoll.o %.c>%.o cspoll.c cspoll
prev cspoll.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c cspoll.c
done cspoll.o generated
make csport.o
make csport.c
prev ${PACKAGE_ast_INCLUDE}/hashkey.h implicit
prev cslib.h implicit
done csport.c
meta csport.o %.c>%.o csport.c csport
prev csport.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csport.c
done csport.o generated
make csread.o
make csread.c
prev cslib.h implicit
done csread.c
meta csread.o %.c>%.o csread.c csread
prev csread.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csread.c
done csread.o generated
make csrecv.o
make csrecv.c
prev cslib.h implicit
done csrecv.c
meta csrecv.o %.c>%.o csrecv.c csrecv
prev csrecv.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csrecv.c
done csrecv.o generated
make cssend.o
make cssend.c
prev cslib.h implicit
done cssend.c
meta cssend.o %.c>%.o cssend.c cssend
prev cssend.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c cssend.c
done cssend.o generated
make css.o
make css.c
prev ${PACKAGE_ast_INCLUDE}/dirent.h implicit
make csslib.h implicit
make css.h implicit
prev cs.h implicit
done css.h dontcare
prev ${PACKAGE_ast_INCLUDE}/tok.h implicit
prev ${PACKAGE_ast_INCLUDE}/sig.h implicit
prev ${PACKAGE_ast_INCLUDE}/error.h implicit
prev cslib.h implicit
done csslib.h
done css.c
meta css.o %.c>%.o css.c css
prev css.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -DDEBUG -D_BLD_cs -D_PACKAGE_ast -c css.c
done css.o generated
make csserve.o
make csserve.c
prev csslib.h implicit
done csserve.c
meta csserve.o %.c>%.o csserve.c csserve
prev csserve.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -DDEBUG -c csserve.c
done csserve.o generated
make csstat.o
make csstat.c
prev ${PACKAGE_ast_INCLUDE}/proc.h implicit
prev cslib.h implicit
done csstat.c
meta csstat.o %.c>%.o csstat.c csstat
prev csstat.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csstat.c
done csstat.o generated
make csto.o
make csto.c
prev cslib.h implicit
done csto.c
meta csto.o %.c>%.o csto.c csto
prev csto.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csto.c
done csto.o generated
make csvar.o
make csvar.c
prev cslib.h implicit
done csvar.c
meta csvar.o %.c>%.o csvar.c csvar
prev csvar.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -DTRUST=\""${INSTALLROOT}:${INSTALLROOT}/opt/ast:/usr/add-on/ast:/usr/addon/ast:/usr/contrib/ast:/usr/local/arch/${mam_cc_HOSTTYPE}/ast:/usr/local/ast:/opt/ast:/usr/local/arch/${mam_cc_HOSTTYPE}:/usr/local:${INSTALLROOT}/opt:/usr/add-on:/usr/addon:/usr/contrib:/usr/local/arch/${mam_cc_HOSTTYPE}:/usr/local:/opt:/:/usr"\" -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c csvar.c
done csvar.o generated
make cswrite.o
make cswrite.c
prev cslib.h implicit
done cswrite.c
meta cswrite.o %.c>%.o cswrite.c cswrite
prev cswrite.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -DDEBUG -D_BLD_cs -c cswrite.c
done cswrite.o generated
make msgblast.o
make msgblast.c
make msglib.h implicit
prev ${PACKAGE_ast_INCLUDE}/ls.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast_dir.h implicit
make msg.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
done msg.h dontcare
prev cs_lib.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
done msglib.h
done msgblast.c
meta msgblast.o %.c>%.o msgblast.c msgblast
prev msgblast.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msgblast.c
done msgblast.o generated
make msgbuf.o
make msgbuf.c
prev msglib.h implicit
done msgbuf.c
meta msgbuf.o %.c>%.o msgbuf.c msgbuf
prev msgbuf.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msgbuf.c
done msgbuf.o generated
make msggetmask.o
make msggetmask.c
prev msglib.h implicit
done msggetmask.c
meta msggetmask.o %.c>%.o msggetmask.c msggetmask
prev msggetmask.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msggetmask.c
done msggetmask.o generated
make msgindex.o
make msgindex.c
prev msglib.h implicit
done msgindex.c
meta msgindex.o %.c>%.o msgindex.c msgindex
prev msgindex.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msgindex.c
done msgindex.o generated
make msginfo.o
make msginfo.c
prev msglib.h implicit
done msginfo.c
meta msginfo.o %.c>%.o msginfo.c msginfo
prev msginfo.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msginfo.c
done msginfo.o generated
make msglist.o
make msglist.c
make ${PACKAGE_ast_INCLUDE}/tm.h implicit
prev ${PACKAGE_ast_INCLUDE}/times.h implicit
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/tm.h
make ${PACKAGE_ast_INCLUDE}/ccode.h implicit
make ${PACKAGE_ast_INCLUDE}/ast_ccode.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_ccode.h dontcare
prev ${PACKAGE_ast_INCLUDE}/ast_common.h implicit
prev ${PACKAGE_ast_INCLUDE}/prototyped.h implicit
done ${PACKAGE_ast_INCLUDE}/ccode.h
prev msglib.h implicit
done msglist.c
meta msglist.o %.c>%.o msglist.c msglist
prev msglist.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_PACKAGE_ast -D_BLD_cs -c msglist.c
done msglist.o generated
make msgname.o
make msgname.c
prev msglib.h implicit
done msgname.c
meta msgname.o %.c>%.o msgname.c msgname
prev msgname.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msgname.c
done msgname.o generated
make msgread.o
make msgread.c
prev cs.h implicit
prev msglib.h implicit
done msgread.c
meta msgread.o %.c>%.o msgread.c msgread
prev msgread.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msgread.c
done msgread.o generated
make msgrecv.o
make msgrecv.c
prev msglib.h implicit
done msgrecv.c
meta msgrecv.o %.c>%.o msgrecv.c msgrecv
prev msgrecv.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msgrecv.c
done msgrecv.o generated
make msgsend.o
make msgsend.c
prev cs.h implicit
prev msglib.h implicit
done msgsend.c
meta msgsend.o %.c>%.o msgsend.c msgsend
prev msgsend.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msgsend.c
done msgsend.o generated
make msgsetmask.o
make msgsetmask.c
prev msglib.h implicit
done msgsetmask.c
meta msgsetmask.o %.c>%.o msgsetmask.c msgsetmask
prev msgsetmask.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msgsetmask.c
done msgsetmask.o generated
make msguser.o
make msguser.c
prev cs.h implicit
prev msglib.h implicit
done msguser.c
meta msguser.o %.c>%.o msguser.c msguser
prev msguser.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -D_BLD_cs -D_PACKAGE_ast -c msguser.c
done msguser.o generated
exec - ${AR} rc libcs.a csalloc.o csfree.o csaddr.o csattr.o csauth.o csbind.o csclient.o cscontrol.o csdaemon.o csdata.o csfrom.o csfull.o csinfo.o cslocal.o csname.o csnote.o csntoa.o csopen.o cspath.o cspeek.o csping.o cspipe.o cspoll.o csport.o csread.o csrecv.o cssend.o css.o csserve.o csstat.o
exec - ${AR} rc libcs.a csto.o csvar.o cswrite.o msgblast.o msgbuf.o msggetmask.o msgindex.o msginfo.o msglist.o msgname.o msgread.o msgrecv.o msgsend.o msgsetmask.o msguser.o
exec - (ranlib libcs.a) >/dev/null 2>&1 || true
done libcs.a generated
done cs virtual
prev libcs.a archive
make genlocal
make genlocal.sh
done genlocal.sh
meta genlocal %.sh>% genlocal.sh genlocal
prev genlocal.sh
exec - case static,port:$OPTIND:$RANDOM in
exec - ?*:*:*|*::*|*:*:$RANDOM)
exec - ;;
exec - *) if ENV= LC_ALL=C x= $SHELL -nc '[[ a || b ]] && : ${list[level]} !(pattern)' 2>/dev/null
exec - then if grep '### .*archaic.* ###' >/dev/null
exec - then : genlocal contains archaic constructs :
exec - else ENV= LC_ALL=C $SHELL -n genlocal.sh
exec - fi
exec - fi
exec - ;;
exec - esac
exec - case '${mam_cc_SHELLMAGIC}' in
exec - "") case 0 in
exec - 0) cp genlocal.sh genlocal
exec - ;;
exec - *) {
exec - i=`(read x; echo $x) < genlocal.sh`
exec - case $i in
exec - '#!'*|*'||'*|':'*|'":"'*|"':'"*) echo "$i" ;;
exec - esac
exec - cat - genlocal.sh <<'!'
exec -
exec - !
exec - } > genlocal
exec - ;;
exec - esac
exec - ;;
exec - *) cat - genlocal.sh > genlocal <<'!'
exec - ${mam_cc_SHELLMAGIC}
exec -
exec - !
exec - ;;
exec - esac
exec - silent test -w genlocal -a -x genlocal || chmod u+w,+x genlocal
done genlocal generated
make genshare
make genshare.sh
done genshare.sh
meta genshare %.sh>% genshare.sh genshare
prev genshare.sh
exec - case static,port:$OPTIND:$RANDOM in
exec - ?*:*:*|*::*|*:*:$RANDOM)
exec - ;;
exec - *) if ENV= LC_ALL=C x= $SHELL -nc '[[ a || b ]] && : ${list[level]} !(pattern)' 2>/dev/null
exec - then if grep '### .*archaic.* ###' >/dev/null
exec - then : genshare contains archaic constructs :
exec - else ENV= LC_ALL=C $SHELL -n genshare.sh
exec - fi
exec - fi
exec - ;;
exec - esac
exec - case '${mam_cc_SHELLMAGIC}' in
exec - "") case 0 in
exec - 0) cp genshare.sh genshare
exec - ;;
exec - *) {
exec - i=`(read x; echo $x) < genshare.sh`
exec - case $i in
exec - '#!'*|*'||'*|':'*|'":"'*|"':'"*) echo "$i" ;;
exec - esac
exec - cat - genshare.sh <<'!'
exec -
exec - !
exec - } > genshare
exec - ;;
exec - esac
exec - ;;
exec - *) cat - genshare.sh > genshare <<'!'
exec - ${mam_cc_SHELLMAGIC}
exec -
exec - !
exec - ;;
exec - esac
exec - silent test -w genshare -a -x genshare || chmod u+w,+x genshare
done genshare generated
make ${INSTALLROOT}/lib
exec - if silent test ! -d ${INSTALLROOT}/lib
exec - then mkdir -p ${INSTALLROOT}/lib
exec - fi
done ${INSTALLROOT}/lib generated
make ${INSTALLROOT}/lib/libcs.a archive
prev ${INSTALLROOT}/lib
prev libcs.a archive
exec - test '' = 'libcs.a' || ${STDCMP} 2>/dev/null -s libcs.a ${INSTALLROOT}/lib/libcs.a || { ${STDMV} ${INSTALLROOT}/lib/libcs.a ${INSTALLROOT}/lib/libcs.a.old 2>/dev/null || true; ${STDCP} libcs.a ${INSTALLROOT}/lib/libcs.a ;}
exec - (ranlib ${INSTALLROOT}/lib/libcs.a) >/dev/null 2>&1 || true
done ${INSTALLROOT}/lib/libcs.a generated
make ${INSTALLROOT}/man/man3
exec - if silent test ! -d ${INSTALLROOT}/man/man3
exec - then mkdir -p ${INSTALLROOT}/man/man3
exec - fi
done ${INSTALLROOT}/man/man3 generated
make ${INSTALLROOT}/man/man3/cs.3
prev ${INSTALLROOT}/man/man3
make cs.3
done cs.3
exec - test '' = 'cs.3' || ${STDCMP} 2>/dev/null -s cs.3 ${INSTALLROOT}/man/man3/cs.3 || { ${STDMV} ${INSTALLROOT}/man/man3/cs.3 ${INSTALLROOT}/man/man3/cs.3.old 2>/dev/null || true; ${STDCP} cs.3 ${INSTALLROOT}/man/man3/cs.3 ;}
done ${INSTALLROOT}/man/man3/cs.3 generated
make ${INSTALLROOT}/lib/lib
exec - if silent test ! -d ${INSTALLROOT}/lib/lib
exec - then mkdir -p ${INSTALLROOT}/lib/lib
exec - fi
done ${INSTALLROOT}/lib/lib generated
make ${INSTALLROOT}/lib/lib/cs
prev ${INSTALLROOT}/lib/lib
prev cs.req
exec - test '' = 'cs.req' || ${STDCMP} 2>/dev/null -s cs.req ${INSTALLROOT}/lib/lib/cs || { ${STDMV} ${INSTALLROOT}/lib/lib/cs ${INSTALLROOT}/lib/lib/cs.old 2>/dev/null || true; ${STDCP} cs.req ${INSTALLROOT}/lib/lib/cs ;}
done ${INSTALLROOT}/lib/lib/cs generated
make ${PACKAGE_ast_INCLUDE}
exec - if silent test ! -d ${PACKAGE_ast_INCLUDE}
exec - then mkdir -p ${PACKAGE_ast_INCLUDE}
exec - fi
done ${PACKAGE_ast_INCLUDE} generated
make ${PACKAGE_ast_INCLUDE}/cs.h
prev ${PACKAGE_ast_INCLUDE}
prev cs.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1990,author=gsf' cs.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/cs.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/cs.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/cs.h generated
make ${PACKAGE_ast_INCLUDE}/css.h
prev css.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1990,author=gsf' css.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/css.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/css.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/css.h generated
make ${PACKAGE_ast_INCLUDE}/msg.h
prev msg.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1990,author=gsf' msg.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/msg.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/msg.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/msg.h generated
make ${PACKAGE_ast_INCLUDE}/ast_cs.h
prev ast_cs.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1990,author=gsf' ast_cs.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/ast_cs.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/ast_cs.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/ast_cs.h generated
make ${PACKAGE_ast_INCLUDE}/cs_lib.h
prev cs_lib.h
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1990,author=gsf' cs_lib.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${PACKAGE_ast_INCLUDE}/cs_lib.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${PACKAGE_ast_INCLUDE}/cs_lib.h
exec - fi
done ${PACKAGE_ast_INCLUDE}/cs_lib.h generated
make ${INSTALLROOT}/lib/cs
exec - if silent test ! -d ${INSTALLROOT}/lib/cs
exec - then mkdir -p ${INSTALLROOT}/lib/cs
exec - fi
done ${INSTALLROOT}/lib/cs generated
make ${INSTALLROOT}/lib/cs/genlocal
prev ${INSTALLROOT}/lib/cs
prev genlocal
exec - test '' = 'genlocal' || ${STDCMP} 2>/dev/null -s genlocal ${INSTALLROOT}/lib/cs/genlocal || { ${STDMV} ${INSTALLROOT}/lib/cs/genlocal ${INSTALLROOT}/lib/cs/genlocal.old 2>/dev/null || true; ${STDCP} genlocal ${INSTALLROOT}/lib/cs/genlocal ;}
done ${INSTALLROOT}/lib/cs/genlocal generated
make ${INSTALLROOT}/lib/cs/genshare
prev genshare
exec - test '' = 'genshare' || ${STDCMP} 2>/dev/null -s genshare ${INSTALLROOT}/lib/cs/genshare || { ${STDMV} ${INSTALLROOT}/lib/cs/genshare ${INSTALLROOT}/lib/cs/genshare.old 2>/dev/null || true; ${STDCP} genshare ${INSTALLROOT}/lib/cs/genshare ;}
done ${INSTALLROOT}/lib/cs/genshare generated
make ${INSTALLROOT}/share/lib/cs
exec - if silent test ! -d ${INSTALLROOT}/share/lib/cs
exec - then mkdir -p ${INSTALLROOT}/share/lib/cs
exec - fi
done ${INSTALLROOT}/share/lib/cs generated
make ${INSTALLROOT}/share/lib/cs/local.ast
prev ${INSTALLROOT}/share/lib/cs
make local.ast
done local.ast
exec - test '' = 'local.ast' || ${STDCMP} 2>/dev/null -s local.ast ${INSTALLROOT}/share/lib/cs/local.ast || { ${STDMV} ${INSTALLROOT}/share/lib/cs/local.ast ${INSTALLROOT}/share/lib/cs/local.ast.old 2>/dev/null || true; ${STDCP} local.ast ${INSTALLROOT}/share/lib/cs/local.ast ;}
done ${INSTALLROOT}/share/lib/cs/local.ast generated
make ${INSTALLROOT}/share/lib/cs/genlocal
prev genlocal
exec - test '' = 'genlocal' || ${STDCMP} 2>/dev/null -s genlocal ${INSTALLROOT}/share/lib/cs/genlocal || { ${STDMV} ${INSTALLROOT}/share/lib/cs/genlocal ${INSTALLROOT}/share/lib/cs/genlocal.old 2>/dev/null || true; ${STDCP} genlocal ${INSTALLROOT}/share/lib/cs/genlocal ;}
done ${INSTALLROOT}/share/lib/cs/genlocal generated
make ${INSTALLROOT}/share/lib/cs/genshare
prev genshare
exec - test '' = 'genshare' || ${STDCMP} 2>/dev/null -s genshare ${INSTALLROOT}/share/lib/cs/genshare || { ${STDMV} ${INSTALLROOT}/share/lib/cs/genshare ${INSTALLROOT}/share/lib/cs/genshare.old 2>/dev/null || true; ${STDCP} genshare ${INSTALLROOT}/share/lib/cs/genshare ;}
done ${INSTALLROOT}/share/lib/cs/genshare generated
make ${INSTALLROOT}/share/lib/cs/tcp
setv mode -Dmode="+rwxt"
exec - if silent test ! -d ${INSTALLROOT}/share/lib/cs/tcp
exec - then mkdir -p ${INSTALLROOT}/share/lib/cs/tcp && chmod ugo+rwxt ${INSTALLROOT}/share/lib/cs/tcp
exec - fi
done ${INSTALLROOT}/share/lib/cs/tcp generated
make ${INSTALLROOT}/share/lib/cs/udp
setv mode -Dmode="+rwxt"
exec - if silent test ! -d ${INSTALLROOT}/share/lib/cs/udp
exec - then mkdir -p ${INSTALLROOT}/share/lib/cs/udp && chmod ugo+rwxt ${INSTALLROOT}/share/lib/cs/udp
exec - fi
done ${INSTALLROOT}/share/lib/cs/udp generated
make ${INSTALLROOT}/lib/make
exec - if silent test ! -d ${INSTALLROOT}/lib/make
exec - then mkdir -p ${INSTALLROOT}/lib/make
exec - fi
done ${INSTALLROOT}/lib/make generated
make ${INSTALLROOT}/lib/make/SERVICE.mk
prev ${INSTALLROOT}/lib/make
make SERVICE.mk
done SERVICE.mk
exec - test '' = 'SERVICE.mk' || ${STDCMP} 2>/dev/null -s SERVICE.mk ${INSTALLROOT}/lib/make/SERVICE.mk || { ${STDMV} ${INSTALLROOT}/lib/make/SERVICE.mk ${INSTALLROOT}/lib/make/SERVICE.mk.old 2>/dev/null || true; ${STDCP} SERVICE.mk ${INSTALLROOT}/lib/make/SERVICE.mk ;}
done ${INSTALLROOT}/lib/make/SERVICE.mk generated
make ${INSTALLROOT}/lib/cs/share
make share
prev genshare
prev FEATURE/lib
make ${INSTALLROOT}/share
done ${INSTALLROOT}/share
exec - if test ! -f share
exec - then {
exec - rsh=`sed -e '/^#define CS_REMOTE_SHELL/!d' -e 's/.*"\(.*\)".*/\1/' FEATURE/lib`
exec - echo "#!!! 1 to update this file: $INSTALLROOT/lib/cs/genshare -d ${INSTALLROOT}/share -r $rsh > share !!!"
exec - } > share
exec - fi
done share generated
exec - if test ! -f ${INSTALLROOT}/lib/cs/share
exec - then cp share ${INSTALLROOT}/lib/cs/share
exec - fi
done ${INSTALLROOT}/lib/cs/share generated
make ${INSTALLROOT}/share/lib/cs/local
make local
prev genlocal
prev FEATURE/lib
prev share
exec - if test ! -f local
exec - then {
exec - rsh=`sed -e '/^#define CS_REMOTE_SHELL/!d' -e 's/.*"\(.*\)".*/\1/' FEATURE/lib`
exec - echo "#!!! 1 to update this file: $INSTALLROOT/lib/cs/genlocal -r $rsh > local !!!"
exec - } > local
exec - fi
done local generated
exec - if test ! -f ${INSTALLROOT}/share/lib/cs/local
exec - then cp local ${INSTALLROOT}/share/lib/cs/local
exec - fi
done ${INSTALLROOT}/share/lib/cs/local generated
done install virtual
make test
done test dontcare virtual

View file

@ -1,90 +0,0 @@
10-06-01 sync with ast api 20100601
10-04-12 Makefile: defer share and local generation to first use
08-04-09 csopen.c: fix mkmount() path cleanup
08-04-09 csopen.c: add debug=-1 mkmount() error message
07-06-05 csclient.c: add CS_CLIENT_SEP
06-09-19 css.c: sysconf() => astconf()
06-08-15 csclient.c: fix prompt logic
06-08-14 csopen.c: fix group=name logic
06-08-04 csclient.c: fix CS_CLIENT_ARGV
06-06-11 csclient.c: add
06-05-31 csopen.c,cs.h: add csattach() for non-/dev/fdp/ streams
05-02-04 Makefile: drop -lnetinet (for lynxos)
04-07-22 csopen.c,cssend.c,csauth.c,cslocal.c: access() => eaccess()
04-07-19 cslocal.c: call spawnveg() for standalone 3d
04-03-25 csrecv.c,cssend.c: OPEN_MAX_CEIL => OPEN_MAX
03-08-01 csdata.c: add NoF pure data workaround, drop const + prototyped
03-03-28 msglib.h: add D_FILENO ifdef
02-10-02 features/lib,genlocal.sh: add ssh, pid to hang warning
msglist.c: tmform() => fmttime()
01-12-12 cssfd: CS_POLL_CLOSE now close()'s if not dropped -- double duh
csstat: change down test to avoid unsigned long overflow
01-10-31 cssend,csrecv: use msg_accrights over msg_control
cspath: don't check /dev/fd/* -- duh
01-05-11 csserve: sync cs.* with css->*
csspoll: handl cspoll() EINTR that doesn't set cs.interrupt
01-01-01 cspoll: fix getmsg() flag arg
csaddr: fix local host addr initialization
00-06-01 csopen: handle dynamic ip assignment underfoot
00-05-11 csopen: handle /dev/tcp/local/9876/FOO/other
00-05-09 cssfd: CS_POLL_WRITE implies O_NONBLOCK
00-02-14 cschallenge(): add stat() to verify touch()
00-02-03 features/lib: add sys/types.h to htons etc. header refs
00-01-25 genlocal: use package instead of hostinfo
99-10-07 csbind: NODELAY for CS_ADDR_NOW only
99-09-22 cs*: add CS_MNT_TAIL for multi-char mount files
css: _UWIN workaround for st_ino verification
99-07-17 csaddr: clear more state->flags bits to avoid prev csopen() carryover
99-05-20 msg*: handle f_basetype and f_fsid for redhat 6.0 linux -- boo
99-05-13 css: fix disc.wakeup logic
cspoll: add debug=6 poll trace
99-04-23 csaddr: check for 127.0.0.[01] from hostname lookup == local
98-06-29 cs.h: add Cs == (&cs)
98-06-03 csserve: fix SIGCHLD exit bug
98-02-14 csopen: add PROC_ZOMBIE for systems that don't fork() in csdaemon()
97-11-27 csopen: /dev/tcp/*/inet.*/user for client inet.* authentication
css.h: add CSS_AUTHENTICATE for server inet.* authentication
97-11-11 csread: add CS_RESTART to restart on interrupt
cslib: CS_AUTH_MODE for authentication file mode
cs.h: drop CS_SVC_SERVICE, add CS_SVC_SUFFIX
SERVICE.mk: executable name changed from server => `service'.svc
csopen: rm CS_MOUNT_PROCESS if no connect and pid invalid
97-07-17 add css.h, csserve() on top of css
CS_INTERFACE=2 for thread safe state instead of global cs.*
cspoll(CS_POLL_WRITE) events cleared on write
csspoll(timeout,CSS_INTERRUPT|CSS_ERROR)
cs.h,msg.h: fix dll import/export
97-05-09 cslib.h: check _hdr_netdb,_hdr_netinet_in,_hdr_netinet_tcp
features/lib: statvfs.f_fstr
msglib.h: <ast.h> before "cs_lib.h"
97-04-01 csport: htons() done too soon
96-12-25 genlocal: add correct nslookup query
fix sizeof(long)==4 assumptions
install genlocal and genshare in $(INSTALLROOT)/lib/$(ID)
96-02-29 use <hashkey.h>
add csport()
drop CS_MOUNT_*; use csvar(CS_VAR_*,trust) instead
CS_VAR_PROXY ($CS_MOUNT_PROXY) names proxy connect stream
csopen() attempts proxy open on local failure
hold CS_PROC_FD_TST cssend() fds until next cssend()
csread(CS_LINE) really means 1 line
fix cslocal() and csopen() fdp initiate timing bug
96-01-31 add warning to local rather than generate on install
96-01-22 no <sys/uio.h> on linux (defined(MAX_IOVEC))
95-11-11 trap 127.0.0.[01] local address alias in cspath() and csntoa()
95-10-31 CS_MNT_OTHER '.' -> '#' to placate NT (trailing . ignored -- thanks)
95-10-11 export -> coexport
add dirsize() to cslib.h
check _mem_d_reclen_dirent for d_reclen
95-08-11 (done)(handle,EXIT_TERM(signal)) called on csserve() interrupt
0 return ignores signal
csserve() now creates local auth dir if not there, duh
fix genlocal hostinfo timeout
95-07-17 fix remote auth off by one error
95-05-09 add linux /proc/<pid>/fd/<fd> to cssend()-csrecv()
add bsd4.4 msghdr.msg_accrights -> msghdr.msg_control mods
bsd4.4 thinks S_ISFIFO() and S_ISSOCK() are the same!
features/cs.c now uses sfio
95-04-01 convert genlocal.sh to hostinfo
95-03-19 bsd4.4 stole devname(), so use devpath() in cspath()
94-12-15 csinfo("-",0) gets standard info

View file

@ -1,45 +0,0 @@
/*
* -lcs service support
*
* @(#)service (AT&T Research) 1997-11-11
*
* service [ type [ mode ] [ dir ] ] :SERVICE: prerequisites
*
* type defaults to tcp, mode defaults to null
*/
if ! SERVICEDIR
SERVICEDIR = $(LIBDIR)/cs
end
SERVICESUFFIX = .svc
":SERVICE:" : .MAKE .OPERATOR
local opt service type mode dir
eval
service = $(<:O=1)
if ! ( type = "$(<:O=2:/,/ /G)" )
type = tcp
end
for opt $(<:O>=3)
if "$(opt:N=-*|*=*)"
mode += $(opt)
else
dir := $(opt)
end
end
$$(SERVICEDIR) :INSTALLDIR:
if dir
$(dir)/$(service) :INSTALL: preserve=1 $(service)$(SERVICESUFFIX)
else
for dir $(type)
$$(SERVICEDIR)/$(dir)/$(service)/$(service)$(SERVICESUFFIX) :INSTALL: preserve=1 $(mode) $(service)$(SERVICESUFFIX)
end
end
for dir $(type)
$$(SERVICEDIR)/$(dir)/$(service) :INSTALLDIR: $(>:N=export|hosts)
end
:INSTALLDIR: $(service)$(SERVICESUFFIX)
$(service)$(SERVICESUFFIX) :: $(>) -l$(SERVICEDIR:B)
:ALL: $(service)$(SERVICESUFFIX)
end

View file

@ -1,472 +0,0 @@
.fp 5 CW
.de L \" literal font
.ft 5
.if !\\$1 \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \f1
..
.de LR
.}S 5 1 \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.de RL
.}S 1 5 \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.de EX \" start example
.ta 1i 2i 3i 4i 5i 6i
.PP
.RS
.PD 0
.ft 5
.nf
..
.de EE \" end example
.fi
.ft
.PD
.RE
.PP
..
.TH CS 3
.SH NAME \" @(#)cs.3 (gsf@research.att.com) 01/01/92
cs \- connect stream ipc support
.SH SYNOPSIS
.L "#include <cs.h>"
.br
.L "\-lcs \-last"
.SH DESCRIPTION
The
.I cs
routines support local and remote connect streams in the file system
name space.
This is a traditional alternative to the service/port database
schemes used by the BSD derivatives and the streams-based alternatives in
10th edition and s5r4.
The interface presented here is the same for all systems that support
sockets or streams.
.PP
Connect stream files allow unrelated processes to rendezvous.
A server first creates a connect stream.
Each client open of the connect stream received by the server presents a unique
bi-directional pipe connection between the client and server.
.PP
Connect streams may be either
.I local
or
.IR remote .
Local connections support file descriptor exchange via
.L cssend
and
.LR csrecv .
.PP
Connect stream names are of the form
\fB/dev/\fP\fIproto\fP\fB/\fP\fIhost\fP\fB/\fP\fIservice\fP[/\fIoptions\fP
.I proto
is
.B fdp
for local streams and
.B tcp
or
.B udp
for remote streams.
.I host
is either a host name or an internet
.I n.n.n.n
address.
.B local
names the local host and
.B share
names any host on the local network that is running the service.
.I service
is either a service name or an integer port number.
The
.I options
are
.B /
separated and further qualify the connect stream:
.TP
\fBuser\fP[=\fIuid\fP]
restricts the connection to the current
.RI [ uid ]
user
.TP
\fBgroup\fP[=\fIgid\fP]
restricts the connection to the current
.RI [ gid ]
group
.TP
.B other
(default) specifies no user or group restrictions.
.TP
.B local
causes a
.B share
service to be instantiated on the local host if it is not already running
.TP
.B remote
causes the host address to be interpreted as remote -- mainly used to
debug remote authentication
.TP
.B slave
used service instantiation to disable the
.L csdaemon
background
.L fork
-- used by master servers to preserve the parent/child relationship
.PP
Other options are service dependent and are used to name different
instantiations of the same service.
.PP
Most servers reside in the directory
\fBlib\fP/\fBcs\fP/\fIproto\fP/\fIservice\fP.
.B server
is the name of the server executable.
The file
.B hosts
lists the hosts on which the service can be automatically started
(see
.L csopen
below).
The first available host will be used.
The special host name
.B share
is expanded to a list of the local network file servers.
If
.B hosts
is omitted then
.B share
is assumed.
.PP
The basic routines are:
.PP
.L "int csopen(const char* path, int flags)"
.PP
Open a unique connection to the process that created the connect stream
.LR path .
The other process must do a
.L csrecv
to complete the rendezvous.
The connection file descriptor is returned,
.L \-1
on error.
If the service is not running and the
.B server
and
.B hosts
files corresponding to the connect stream are located then the service HERE
.PP
.L "char* cspath(int fd)"
.PP
Return a pointer to an equivalent pathname for the open file descriptor
.LR fd .
.PP
.L "int cspoll(int nfds, fd_set* rd, fd_set* wr, long ms)"
.PP
Poll the file descriptors
.L 0
through
.L nfds\-1
in
.L rd
for read events (data available for
.L read
or
.LR csrecv )
and
.L wr
for write events
.RL ( write
or
.L cssend
possible).
.LR rd ( wr )
may be
.L 0
if read(write)
events are not of interest.
The number of file descriptors matching the requested events is returned,
and
.L rd
and
.L wr
are modified to reflect the matched file descriptors.
.L cspoll
will timeout after
.L ms
milliseconds.
If
.L ms
is
.L \-1
then
.L cspoll
will block until one of the requested events occurs.
.L 0
is returned if no events occurred before the timeout,
.L \-1
on error.
.L fd_set
variables are manipulated by the following functions:
.RS
.TP
.L "FD_NEW(fd_set* set)"
Initialize
.L set
with no elements.
.TP
.L "FD_SET(int fd, fd_set* set)"
Add
.L fd
to
.LR set .
.TP
.L "FD_CLR(int fd, fd_set* set)"
Remove
.L fd
from
.LR set .
.TP
.L "FD_TST(int fd, fd_set* set)"
Return non-zero if
.L fd
is a member of
.LR set .
.RE
.PP
.L "int csrecv(int fd, CSID* id, int* fds, int nfds)"
.PP
Receive up to
.L nfds
file descriptors from the stream
.L fd
and place them in the array pointed to by
.LR fds .
The number of received file descriptors is returned,
.L \-1
on error.
.L csrecv
is used under two circumstances:
the first is
to complete a rendezvous on a connect stream initiated by a
.L csopen
in another process; the second is to receive file descriptors
on any stream initiated by a
.L cssend
in another process.
For local streams
.L id\->hid
is set to
.L 0
and
.LR id\->pid ,
.LR id\->uid ,
and
.LR id\->gid
are set to the process id, user id and group id of the sending process.
For remote streams
.LR id\->hid
is set to the internet address of the sending process and the remaining
elements are undefined.
In any event, only the uid and gid can currently be trusted.
.PP
.L "int cssend(int fd, int* fds, int nfds)"
.PP
Send
.L nfds
file descriptors pointed to by
.L fds
on the stream
.LR fd .
.L 0
is returned on success,
.L \-1
on error.
.L csrecv
is used on the other side of
.L fd
to receive the file descriptors.
.L cssend
may return before
.L csrecv
completes on the other side.
.PP
The following routines provide portable interfaces for server
related operations.
.PP
.L "unsigned long csaddr(char* name, int cache)"
.PP
Return the internet address for the host
.LR name .
If
.L cache
is greater than zero then intermediate information will be
cached for subsequent
.L csaddr
requests.
If
.L cache
is less than zero then the previous
.L cached
value is retained.
Otherwise caching is turned off.
.L 0
is returned on error.
.PP
.L "int csdaemon()"
.PP
Fork into the background and drop the controlling terminal.
.L 0
is returned on success,
.L \-1
on error.
.PP
.L "int csfdmax()"
.PP
Return the per-process maximum number of open file descriptors.
At least
.L 20
will be returned.
.PP
.L "unsigned long csinet(char* path, unsigned short* port, int* prot)"
.PP
Parse the internet address and optional port number from the path name
.L path
and return the address.
If
.L port
is non-zero then it is set to point to the port number.
If omitted the default port number is
.LR 0 .
.L 0
is returned on error.
If
.L prot
is non-zero then it is set to one of
.L CS_TCP
or
.L CS_UDP
depending on the protocol.
.PP
.L "char* csname()"
.PP
Return a pointer to the local host name.
A non-null pointer is always returned.
.PP
.L "int csnote(char* name, CSSTAT* sp)"
.PP
Note a change to the host status for
.LR name .
This routine is used by the system status demon
.IR ssd (8)
and is the write counterpart of
.LR csstat .
See
.L csstat
below for a description of the
.L CSSTAT
members.
The current working directory must be
.L CS_STAT_DIR
and the calling process must own the local host status file.
.L 0
is returned on success,
.L \-1
on error.
.PP
.L "char* csntoa(unsigned long addr)"
.PP
Return the
.I n.n.n.n
string address for
.LR addr .
.PP
.L "int csstat(char* name, CSSTAT* sp)"
.PP
Return status information in
.L sp
for the host
.LR name .
The information is updated by the system status demon
.IR ssd (8)
using
.LR csnote .
Updates are on average every
.L CS_STAT_FREQ
seconds.
The update frequency is randomized to avoid synchronized update spikes
from multiple hosts.
A host is considered down if its status information is more than
.L CS_STAT_DOWN
seconds old.
.L 0
is returned on success,
.L \-1
on error.
.L CSSTAT
contains the following members:
.RS
.TP
.L "long up"
System uptime in seconds.
If negative then the system has been down for at least
.L \-up
seconds.
.TP
.L "int load"
The 1 minute system load average times 100.
.TP
.L "unsigned long idle"
The minimum idle time in seconds for all users logged into the system.
Keyboard strokes and mouse movement are included in the calculation.
.TP
.L "int users"
The number of users that have been active within the last 24 hours.
.TP
.L "int pctusr"
The percentage of CPU time used by user and low priority processes.
.TP
.L "int pctsys"
The percentage of CPU time used by the system itself.
The cpu idle time is
.LR 100\-(pctusr+pctsys) .
.RE
.SH CAVEATS
Mounting streams in the file system and sending file descriptors
between processes is tricky business.
Most systems can be coaxed to panic with just the right sequence of events.
This library has been written to narrow the panic windows, but there
is still opportunity for crashes.
For example (unless you are at a trade show):
on s5r4, don't unlink a connect stream path while a server
has it open; and on BSD don't kill a client while a
.L cssend
is pending to a hung server until after the server has been killed.
The latter can only happen if the server hangs after the
.L cssend
request has been initiated.
.PP
On some systems the
.L cspoll
millisecond timeout is rounded up to the nearest second.
.PP
For remote connect stream path names the
.I service
component, if it is not registered in the service table,
is hashed to generate a 16 bit TCP port number above
.L IPPORT_USERRESERVED
[5000].
The hashed port number for a given
.I service
will be the same on all systems.
It is possible for two distinct paths to generate the same port number,
but this is also the case for independently administered service tables.
However, if port number clashes become a problem then a name service will be
transparently slipped in to
provide a 1-1 mapping between path names and port numbers.
If
.I service
is
.L 0
for
.L cscreat
then the system generates a port number, usually below
.LR IPPORT_USERRESERVED .
.SH "SEE ALSO"
ss(1), libx(3), ssd(8)

View file

@ -1,355 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* connect stream interface definitions
*/
#ifndef _CS_H
#define _CS_H
#define CS_VERSION 19970717L
#include <ast.h>
#include <ast_cs.h>
#include <hashpart.h>
#include <ls.h>
#include <times.h>
#define cs _cs_info_
#define Cs (&cs)
#define CSTIME() (cs.time=(unsigned long)time(NiL))
#define CSTOSS(n,c) HASHPART(n,c)
#define CS_LOCAL (-1L) /* local address */
#define CS_NEVER (-1L) /* no timeout */
#define CS_EXACT 0x0001 /* csread() exact amount */
#define CS_LIMIT 0x0002 /* csread() amount limit */
#define CS_LINE 0x0004 /* csread() one or more lines */
#define CS_RESTART 0x1000 /* restart on interrupt */
#define CS_PORT_NORMAL 0x00000000 /* alloc normal port */
#define CS_PORT_MIN 0x00000001 /* min real port */
#define CS_PORT_MAX 0x0000ffff /* max real port */
#define CS_PORT_INVALID 0xffffffff /* invalid port */
#define CS_PORT_RESERVED 0xfffffffe /* alloc reserved port */
#define CS_NORMAL CS_PORT_NORMAL
#define CS_RESERVED CS_PORT_RESERVED
#define CS_HOST_GATEWAY "ftp" /* local net gateway host */
#define CS_HOST_LOCAL "local" /* local host */
#define CS_HOST_PROXY "proxy" /* local net proxy host */
#define CS_HOST_SHARE "share" /* any local net host */
#define CS_HOST_UNKNOWN "unknown" /* unknown host */
#define CS_STAT_DAEMON "lib/ssd" /* system stat daemon rel name */
#define CS_STAT_DIR "share/lib/ss" /* system stat dir rel path */
#define CS_STAT_DOWN (3*CS_STAT_FREQ)/* assumed down after . secs */
#define CS_STAT_FREQ 50 /* avg update frequency in secs */
#define CS_STAT_IGNORE (24*60*60) /* ignore user after . idle */
#define CS_SVC_ACCESS "access" /* local host access */
#define CS_SVC_DIR "lib/cs" /* service directory */
#define CS_SVC_DORMANT (5*60) /* min dormant secs */
#define CS_SVC_HOSTS "hosts" /* hosts that can run service */
#define CS_SVC_INFO "local" /* local host info */
#define CS_SVC_REMOTE "remote" /* remote gateway info */
#define CS_SVC_SUFFIX ".svc" /* service daemon suffix */
#define CS_MNT_MAX 14 /* max mount file name length */
#define CS_NAME_MAX 256 /* misc name max length */
#define CS_MNT_TAIL "-cs.mnt" /* mount file name tail */
#define CS_MNT_AUTH 'A' /* client authentication */
#define CS_MNT_LOCK 'X' /* mount lock */
#define CS_MNT_LOG 'L' /* error log */
#define CS_MNT_OLDLOG 'O' /* previous error log */
#define CS_MNT_OTHER '#' /* no auth suffix */
#define CS_MNT_PROCESS 'P' /* process id */
#define CS_MNT_STREAM 'S' /* connect stream */
#define CS_MNT_TMP 'Z' /* temporary */
#define CS_REMOTE_CONTROL "cs"
#define CS_REMOTE_DEBUG 'd'
#define CS_REMOTE_DELAY 8
#define CS_REMOTE_OPEN 'O'
#define CS_REMOTE_OPEN_AGENT 'A'
#define CS_REMOTE_OPEN_LOCAL 'L'
#define CS_REMOTE_OPEN_NOW 'N'
#define CS_REMOTE_OPEN_READ 'R'
#define CS_REMOTE_OPEN_SHARE 'S'
#define CS_REMOTE_OPEN_TEST 'T'
#define CS_REMOTE_OPEN_TRUST 'X'
#define CS_REMOTE_PROFILE "set true; $1 eval 'unset true eval; source ./.login >& /dev/null < /dev/null'; set eval CsH=true; $1 $CsH 'shift; shift; . ./.profile >/dev/null 2>&1 </dev/null'"
#define CS_FD_ALLOCATE (-2) /* csfd() table alloc */
#define CS_OPEN_READ 0 /* initiate and open for read */
#define CS_OPEN_CREATE 1 /* create */
#define CS_OPEN_AGENT (1<<1) /* initiate, no authenticate */
#define CS_OPEN_LOCAL (1<<2) /* CS_OPEN_READ local affinity */
#define CS_OPEN_MOUNT (1<<3) /* no open, mount namespace only*/
#define CS_OPEN_NOW (1<<4) /* non blocking open */
#define CS_OPEN_REMOTE (1<<5) /* force CS_ADDR_REMOTE */
#define CS_OPEN_SHARE (1<<6) /* share affinity */
#define CS_OPEN_SLAVE (1<<7) /* no daemon fork() on create */
#define CS_OPEN_TEST (1<<8) /* open for read, no initiate */
#define CS_OPEN_TRUST (1<<9) /* trusted service */
#define CS_PATH_NAME (1<<0) /* cspath addr name vs. n.n.n.n */
#define CS_VAR_LOCAL 0 /* csvar for local mount dir */
#define CS_VAR_PROXY 1 /* csvar for proxy service */
#define CS_VAR_SHARE 2 /* csvar for share mount dir */
#define CS_VAR_TRUST 3 /* csvar for trusted root dirs */
/*
* cs.flags -- CS_<function>_<flags>
*/
#define CS_ADDR_FULL (1<<0) /* retain fully qualified names */
#define CS_ADDR_LOCAL (1<<1) /* local host */
#define CS_ADDR_NOW (1<<2) /* for CS_OPEN_NOW */
#define CS_ADDR_NUMERIC (1<<3) /* n.n.n.n addr */
#define CS_ADDR_REMOTE (1<<4) /* remote host */
#define CS_ADDR_SHARE (1<<5) /* share host */
#define CS_ADDR_TEST (1<<6) /* share host */
#define CS_ADDR_TRUST (1<<7) /* for CS_OPEN_TRUST */
#define CS_DAEMON_SLAVE (1<<8) /* no daemon fork() */
#define CS_PIPE_BLOCKED (1<<9) /* SIGPIPE blocked */
#define CS_TEST (1<<10) /* enable test */
#define CS_CLIENT_ARGV (1<<0) /* just process argv */
#define CS_CLIENT_RAW (1<<1) /* tty raw mode input */
#define CS_CLIENT_SEP (1<<2) /* argv ':' line sep */
typedef struct
{
unsigned long addr[3]; /* address cookie */
} Csaddr_t;
typedef struct
{
unsigned long hid; /* host id */
unsigned long pid; /* process id */
unsigned long uid; /* user id */
unsigned long gid; /* group id */
} Csid_t;
typedef struct
{
unsigned long idle; /* min user idle secs */
long up; /* up (down<0) time in secs */
int load; /* load average */
int pctsys; /* % time for sys */
int pctusr; /* % time for usr */
int users; /* # interesting users */
} Csstat_t;
struct Cs_s;
typedef struct Cs_s Cs_t;
struct Csdisc_s;
typedef struct Csdisc_s Csdisc_t;
struct Csdisc_s /* user discipline */
{
unsigned long version; /* CS_VERSION */
unsigned long flags; /* CS_* flags */
Error_f errorf; /* error message handler */
};
struct Cs_s /* thread state */
{
char* id; /* library id */
Csdisc_t* disc; /* discipline from csalloc() */
unsigned long addr; /* addr from csbind() */
unsigned long port; /* port from csbind() */
unsigned long time; /* time updated by CSTIME() */
unsigned long flags; /* misc flags */
char* control; /* CS_MNT_* in cs.mount */
char* cs; /* service connect stream */
char type[8]; /* csopen() stream type */
char qual[CS_NAME_MAX];/* csopen() qualifier */
char host[CS_NAME_MAX];/* csaddr() real host */
char mount[PATH_MAX];/* current mount path */
char user[CS_NAME_MAX];/* csaddr() user */
#ifdef _CS_PRIVATE_
_CS_PRIVATE_
#endif
};
#if _BLD_cs && defined(__EXPORT__)
#define extern __EXPORT__
#endif
#if !_BLD_cs && defined(__IMPORT__)
#define extern extern __IMPORT__
#endif
extern Cs_t cs;
#undef extern
#if _BLD_cs && defined(__EXPORT__)
#define extern __EXPORT__
#endif
#if CS_INTERFACE <= 1
#define Cs_addr_t Csaddr_t
#define Cs_id_t Csid_t
#define Cs_info_t Cs_t
#define Cs_poll_t Cspoll_t
#define Cs_stat_t Csstat_t
#define CSADDR Csaddr_t
#define CSID Csid_t
#define CSINFO Csinfo_t
#define CSPOLL Cspoll_t
#define CSSTAT Csstat_t
#define csaddr _cs_addr
#define csattach _cs_attach
#define csattr _cs_attr
#define csauth _cs_auth
#define csbind _cs_bind
#define csclient _cs_client
#define csclone _cs_clone
#define cschallenge _cs_challenge
#define csdaemon _cs_daemon
#define csfd _cs_fd
#define csfrom _cs_from
#define csfull _cs_full
#define csinfo _cs_info
#define cslocal _cs_local
#define csname _cs_name
#define csnote _cs_note
#define csntoa _cs_ntoa
#define csopen _cs_open
#define cspath _cs_path
#define cspeek _cs_peek
#define csping _cs_ping
#define cspipe _cs_pipe
#define cspoll _cs_poll
#define csport _cs_port
#define csread _cs_read
#define csrecv _cs_recv
#define cssend _cs_send
#define csserve _cs_serve
#define csstat _cs_stat
#define cstimeout _cs_timeout
#define csto _cs_to
#define csvar _cs_var
#define cswakeup _cs_wakeup
#define cswrite _cs_write
#else
extern unsigned long csaddr(Cs_t*, const char*);
extern Cs_t* csalloc(Csdisc_t*);
extern int csattach(Cs_t*, const char*, int, int);
extern char* csattr(Cs_t*, const char*, const char*);
extern int csauth(Cs_t*, int, const char*, const char*);
extern int csbind(Cs_t*, const char*, unsigned long, unsigned long, unsigned long);
extern int cschallenge(Cs_t*, const char*, unsigned long*, unsigned long*);
extern int csclient(Cs_t*, int, const char*, const char*, char**, unsigned int);
extern unsigned long csclone(Cs_t*, int);
extern int csdaemon(Cs_t*, int);
extern int csfd(Cs_t*, int, int);
extern int csfree(Cs_t*);
extern ssize_t csfrom(Cs_t*, int, void*, size_t, Csaddr_t*);
extern char* csfull(Cs_t*, unsigned long);
extern Sfio_t* csinfo(Cs_t*, const char*, int*);
extern int cslocal(Cs_t*, const char*);
extern char* csname(Cs_t*, unsigned long);
extern int csnote(Cs_t*, const char*, Csstat_t*);
extern char* csntoa(Cs_t*, unsigned long);
extern int csopen(Cs_t*, const char*, int);
extern char* cspath(Cs_t*, int, int);
extern ssize_t cspeek(Cs_t*, int, void*, size_t);
extern int csping(Cs_t*, const char*);
extern int cspipe(Cs_t*, int*);
extern int cspoll(Cs_t*, Cspoll_t*, int, int);
extern unsigned long csport(Cs_t*, const char*, const char*);
extern ssize_t csread(Cs_t*, int, void*, size_t, int);
extern int csrecv(Cs_t*, int, Csid_t*, int*, int);
extern int cssend(Cs_t*, int, int*, int);
extern void csserve(Cs_t*, void*, const char*, void*(*)(void*, int), int(*)(void*, int), int(*)(void*, int, Csid_t*, int, char**), int(*)(void*, int), int(*)(void*, int), int(*)(void*));
extern int csstat(Cs_t*, const char*, Csstat_t*);
extern unsigned long cstimeout(Cs_t*, unsigned long);
extern ssize_t csto(Cs_t*, int, const void*, size_t, Csaddr_t*);
extern char* csvar(Cs_t*, int, int);
extern unsigned long cswakeup(Cs_t*, unsigned long);
extern ssize_t cswrite(Cs_t*, int, const void*, size_t);
#endif
#if CS_INTERFACE <= 1 || defined(_CS_PRIVATE_)
extern unsigned long _cs_addr(const char*);
extern int _cs_attach(const char*, int, int);
extern char* _cs_attr(const char*, const char*);
extern int _cs_auth(int, const char*, const char*);
extern int _cs_bind(const char*, unsigned long, unsigned long, unsigned long);
extern int _cs_client(int, const char*, const char*, char**, unsigned int);
extern unsigned long _cs_clone(int);
extern int _cs_daemon(int);
extern int _cs_fd(int, int);
extern ssize_t _cs_from(int, void*, size_t, Csaddr_t*);
extern char* _cs_full(unsigned long);
extern Sfio_t* _cs_info(const char*, int*);
extern int _cs_local(const char*);
extern char* _cs_name(unsigned long);
extern int _cs_note(const char*, Csstat_t*);
extern char* _cs_ntoa(unsigned long);
extern int _cs_open(const char*, int);
extern char* _cs_path(int, int);
extern ssize_t _cs_peek(int, void*, size_t);
extern int _cs_ping(const char*);
extern int _cs_pipe(int*);
extern int _cs_poll(Cspoll_t*, int, int);
extern unsigned long _cs_port(const char*, const char*);
extern ssize_t _cs_read(int, void*, size_t, int);
extern int _cs_recv(int, Csid_t*, int*, int);
extern int _cs_send(int, int*, int);
extern void _cs_serve(void*, const char*, void*(*)(void*, int), int(*)(void*, int), int(*)(void*, int, Csid_t*, int, char**), int(*)(void*, int), int(*)(void*, int), int(*)(void*));
extern int _cs_stat(const char*, Csstat_t*);
extern unsigned long _cs_timeout(unsigned long);
extern ssize_t _cs_to(int, const void*, size_t, Csaddr_t*);
extern char* _cs_var(int, int);
extern unsigned long _cs_wakeup(unsigned long);
extern ssize_t _cs_write(int, const void*, size_t);
#endif
#undef extern
#endif

View file

@ -1,317 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return the address of a host given its name
*/
#include "cslib.h"
union nl
{
unsigned char c[4];
uint32_t l;
};
static unsigned long local;
/*
* real name to address conversion
*/
static unsigned long
realaddr(register Cs_t* state, const char* name)
{
register int n;
register const char* s;
int r;
const char* t;
union nl addr;
#if CS_LIB_SOCKET
register struct hostent* hp;
#endif
messagef((state->id, NiL, -8, "realaddr(%s) call", name));
state->flags &= ~CS_ADDR_NUMERIC;
s = name;
if (streq(s, CS_HOST_LOCAL))
{
messagef((state->id, NiL, -8, "realaddr(%s) = %s, flags = |%s%s%s", name, csntoa(state, local), (state->flags & CS_ADDR_LOCAL) ? "LOCAL|" : "", (state->flags & CS_ADDR_REMOTE) ? "REMOTE|" : "", (state->flags & CS_ADDR_SHARE) ? "SHARE|" : ""));
return local;
}
/*
* check for 0xX.X.X.X or n.n.n.n
*/
if (*s == '0' && *(s + 1) == 'x')
{
s += 2;
r = 16;
}
else r = 0;
addr.l = 0;
n = 0;
do
{
addr.c[n] = strtol(s, (char**)&t, r) & 0xff;
if (t == s) break;
s = t;
} while (++n < 4 && *s && *s++ == '.');
if (!*s && n == 4)
{
if (!addr.l || addr.c[0] == 127 && addr.c[1] == 0 && addr.c[2] == 0 && addr.c[3] <= 1)
{
addr.l = csaddr(state, NiL);
if (local == CS_LOCAL)
{
addr.c[0] = 127;
addr.c[1] = 0;
addr.c[2] = 0;
addr.c[3] = 1;
local = addr.l;
}
else
addr.l = local;
}
state->flags |= CS_ADDR_NUMERIC;
messagef((state->id, NiL, -8, "realaddr(%s) = %s, flags = |%s%s%s", name, csntoa(state, addr.l), (state->flags & CS_ADDR_LOCAL) ? "LOCAL|" : "", (state->flags & CS_ADDR_REMOTE) ? "REMOTE|" : "", (state->flags & CS_ADDR_SHARE) ? "SHARE|" : ""));
return addr.l;
}
/*
* local conversion
*/
csdb(state);
#if CS_LIB_V10 || CS_LIB_SOCKET
#if CS_LIB_V10
if ((addr.l = (unsigned long)in_address(name)) == INADDR_ANY)
addr.l = 0;
#else
addr.l = ((hp = gethostbyname(name)) && hp->h_addrtype == AF_INET && hp->h_length <= sizeof(struct in_addr)) ? (unsigned long)((struct in_addr*)hp->h_addr)->s_addr : 0;
#endif
if (addr.c[0] == 127 && addr.c[1] == 0 && addr.c[2] == 0 && addr.c[3] <= 1)
{
if (local == CS_LOCAL)
local = addr.l;
else
addr.l = local;
}
messagef((state->id, NiL, -8, "realaddr(%s) = %s, flags = |%s%s%s", name, csntoa(state, addr.l), (state->flags & CS_ADDR_LOCAL) ? "LOCAL|" : "", (state->flags & CS_ADDR_REMOTE) ? "REMOTE|" : "", (state->flags & CS_ADDR_SHARE) ? "SHARE|" : ""));
#else
messagef((state->id, NiL, -8, "realaddr(%s) not found", name));
addr.l = 0;
#endif
return addr.l;
}
/*
* address conversion with CS_HOST_* aliases
* 0 returned on failure
* on success:
*
* state->flags CS_ADDR_* changed to match real host name
* state->host real host name after aliases and local truncation
*/
unsigned long
csaddr(register Cs_t* state, const char* aname)
{
register char* name = (char*)aname;
register char* s;
register unsigned long addr;
register Sfio_t* sp = 0;
int userlen = 0;
int dot = 0;
long flags = 0;
char* user;
messagef((state->id, NiL, -8, "addr(%s) call", name));
if (!local)
{
#if CS_LIB_SOCKET
if (!state->db)
state->db = -1;
#endif
local = CS_LOCAL;
if (addr = realaddr(state, csname(state, 0)))
local = addr;
}
if (!name)
{
addr = local;
goto ok;
}
if (s = strchr(name, '@'))
{
userlen = s - name;
user = name;
name = s + 1;
}
if (strneq(name, CS_HOST_SHARE, sizeof(CS_HOST_SHARE) - 1))
switch (name[sizeof(CS_HOST_SHARE) - 1])
{
case 0:
flags |= CS_ADDR_SHARE;
if (sp = csinfo(state, name, NiL))
{
while (name = sfgetr(sp, '\n', 1))
if (addr = realaddr(state, name))
goto ok;
sfclose(sp);
sp = 0;
}
if (!(addr = realaddr(state, name = CS_HOST_GATEWAY)))
addr = local;
goto ok;
case '.':
flags |= CS_ADDR_SHARE;
name += sizeof(CS_HOST_SHARE);
break;
}
if (addr = realaddr(state, name))
goto ok;
if ((flags & CS_ADDR_SHARE) && !(state->flags & CS_ADDR_NUMERIC) && (s = strchr(name, '.')))
{
char* sb;
char* se;
char* sx;
char* t;
char* te;
dot = s - name;
s = state->temp;
sx = &state->temp[sizeof(state->temp) - 1];
s += sfsprintf(s, sx - s, "%s/", CS_SVC_REMOTE);
sb = s;
se = 0;
t = name;
while (*t && s < sx)
{
if (s - sb >= CS_MNT_MAX)
{
if (se)
{
s = se - 1;
t = te;
}
else
{
if (s >= sx) break;
if (*t == '.') t++;
}
*s++ = '/';
sb = s;
se = 0;
}
if ((*s++ = *t++) == '.')
{
se = s;
te = t;
}
}
*s = 0;
if (sp = csinfo(state, state->temp, NiL))
{
while (t = sfgetr(sp, '\n', 1))
{
if (s = strchr(t, '@')) s++;
else s = t;
if (addr = realaddr(state, s))
{
name = s;
if (!userlen && s != t)
{
userlen = s - t - 1;
user = t;
}
goto ok;
}
}
sfclose(sp);
sp = 0;
}
sfsprintf(state->temp, sizeof(state->temp), "%s.%s", CS_HOST_GATEWAY, name);
if (addr = realaddr(state, state->temp))
{
name = state->temp;
goto ok;
}
sfsprintf(state->temp, sizeof(state->temp), "%-.*s.%s", dot, name, name);
if (addr = realaddr(state, state->temp))
{
name = state->temp;
goto ok;
}
}
messagef((state->id, NiL, -1, "addr: %s: not found", aname));
return 0;
ok:
if (state->flags & CS_ADDR_NUMERIC)
flags &= ~CS_ADDR_SHARE;
if (addr == local)
{
flags |= CS_ADDR_LOCAL;
name = csname(state, 0);
}
else if (!(state->flags & CS_ADDR_NUMERIC))
{
if (s = strchr(name, '.'))
{
sfsprintf(state->temp, sizeof(state->temp), "%-.*s", s - name, name);
if (realaddr(state, state->temp) == addr)
name = state->temp;
else flags |= CS_ADDR_REMOTE;
}
if (!(flags & CS_ADDR_REMOTE) && !streq(name, CS_HOST_PROXY) && !csattr(state, name, "*"))
flags |= CS_ADDR_REMOTE;
}
/*
* cache host name and user for possible CS_REMOTE_SHELL
*/
strncpy(state->host, name, sizeof(state->host) - 1);
if (userlen)
{
if (userlen >= sizeof(state->user)) userlen = sizeof(state->user) - 1;
strncpy(state->user, user, userlen);
}
state->user[userlen] = 0;
if (sp) sfclose(sp);
state->flags &= ~(CS_ADDR_LOCAL|CS_ADDR_NOW|CS_ADDR_REMOTE|CS_ADDR_SHARE|CS_DAEMON_SLAVE|CS_ADDR_TEST|CS_ADDR_TRUST);
state->flags |= flags;
messagef((state->id, NiL, -8, "addr(%s) = %s, flags = |%s%s%s", aname, csntoa(state, addr), (state->flags & CS_ADDR_LOCAL) ? "LOCAL|" : "", (state->flags & CS_ADDR_REMOTE) ? "REMOTE|" : "", (state->flags & CS_ADDR_SHARE) ? "SHARE|" : ""));
return addr;
}
unsigned long
_cs_addr(const char* aname)
{
return csaddr(&cs, aname);
}

View file

@ -1,47 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* allocate cs state context
*/
#include "cslib.h"
Cs_t*
csalloc(Csdisc_t* disc)
{
register Cs_t* state;
if (state = newof(0, Cs_t, 1, 0))
{
state->id = cs.id;
state->disc = disc ? disc : cs.disc;
#if _stream_peek
state->nostream = -1;
#endif
#if _socket_peek
state->nosocket = -1;
#endif
}
return state;
}

View file

@ -1,191 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return the local attr attributes for host name
*/
#include "cslib.h"
#include <ctype.h>
#include <hash.h>
typedef struct
{
HASH_HEADER;
char data[1];
} Info_t;
/*
* load the info from the local info file
*/
static Hash_table_t*
load(register Cs_t* state)
{
register char* s;
char* h;
register Info_t* ip;
register Sfio_t* sp;
register Hash_table_t* tp;
int c;
if (!(sp = csinfo(state, NiL, NiL))) return 0;
if (tp = hashalloc(NiL, HASH_set, HASH_ALLOCATE, HASH_name, "state->info", 0))
while (s = sfgetr(sp, '\n', 1))
{
while (isspace(*s)) s++;
h = s;
while (!isspace(*s) && *s) s++;
if (*s)
{
c = *s;
*s++ = 0;
if (!(ip = (Info_t*)hashlook(tp, h, HASH_CREATE|HASH_SIZE(sizeof(Info_t)+strlen(s)+1), NiL)))
{
hashfree(tp);
tp = 0;
break;
}
*--s = c;
strcpy(ip->data, s);
}
}
sfclose(sp);
return tp;
}
/*
* info cached on first call and return value placed in static buffer ...
* if name==0 || name=="-" then all valid records returned by successive
* csattr() calls until 0 return
* if attr==0 || attr=="-" then all attributes returned
*/
char*
csattr(register Cs_t* state, const char* name, const char* attr)
{
register char* s;
register char* b;
register char* x;
register char* v;
register Info_t* ip;
int n;
unsigned long addr;
static Hash_table_t* tp;
static Hash_position_t* pt;
static char buf[256];
messagef((state->id, NiL, -8, "attr(%s,%s) call", name, attr));
if (!tp && !(tp = load(state)))
return 0;
if (attr && (!*attr || *attr == '-' && !*(attr + 1)))
attr = 0;
b = buf;
x = &buf[sizeof(buf) - 1];
if (!name || *name == '-' && !*(name + 1))
{
name = 0;
scan:
if (!pt && !(pt = hashscan(tp, 0)))
return 0;
n = attr && streq(attr, "name");
do if (!(ip = (Info_t*)hashnext(pt)))
{
hashdone(pt);
pt = 0;
return 0;
} while (n && streq(ip->name, CS_HOST_LOCAL));
if (n)
return ip->name;
if (attr && streq(attr, "*"))
return buf;
b += sfsprintf(b, x - b, "%s", ip->name);
}
else
{
if (streq(name, CS_HOST_LOCAL))
name = (const char*)csname(state, 0);
if (!(ip = (Info_t*)hashlook(tp, name, HASH_LOOKUP, NiL)))
return 0;
if (attr)
{
if (streq(attr, "*"))
return buf;
if (streq(attr, "name"))
return csaddr(state, ip->name) ? state->host : ip->name;
if (streq(attr, "addr") || streq(attr, "host"))
{
if (addr = csaddr(state, ip->name))
return *attr == 'a' ? csntoa(state, addr) : state->host;
return CS_HOST_UNKNOWN;
}
}
}
if (!attr)
{
v = ip->data;
if (b == buf) while (isspace(*v)) v++;
b += sfsprintf(b, x - b, "%s", v);
if (addr = csaddr(state, ip->name))
{
if (!streq(ip->name, state->host))
b += sfsprintf(b, x - b, " host=%s", state->host);
b += sfsprintf(b, x - b, " addr=%s", csntoa(state, addr));
}
}
else if (streq(attr, "addr") || streq(attr, "host"))
b += sfsprintf(b, x - b, " %s", (addr = csaddr(state, ip->name)) ? (*attr == 'a' ? csntoa(state, addr) : state->host) : CS_HOST_UNKNOWN);
else for (v = ip->data;;)
{
while (isspace(*v)) v++;
if (!*v)
{
if (!name)
{
b = buf;
goto scan;
}
return 0;
}
for (s = (char*)attr; *s && *v == *s++; v++);
if (!*s && (*v == '=' || !*v || isspace(*v)))
{
if (*v == '=') v++;
else v = "1";
if (b > buf && b < x) *b++ = ' ';
while (b < x && !isspace(*v) && (*b++ = *v++));
break;
}
while (*v && !isspace(*v)) v++;
}
*b = 0;
return buf;
}
char*
_cs_attr(const char* name, const char* attr)
{
return csattr(&cs, name, attr);
}

View file

@ -1,255 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* authenticate fd given service authentication path
* if path==0 then it is requested from server
* otherwise if fd>=0 then state->host and state->flags are assumed valid
* only used by tcp streams
* fd<0 for remote authentication on fd 0,1
*
* csauth(state,fd,path,arg) called by csopen()
* csauth(state,-1,path,arg) called by `cs -O...'
* csauth(state,fd,0,arg) normal user call
*/
#include "cslib.h"
#include <error.h>
#define AUTH_BASE 1000
int
csauth(register Cs_t* state, int fd, const char* path, const char* arg)
{
register char* s;
register char* t;
char* b;
char* key = 0;
int n;
int m;
int wfd;
unsigned long t1;
unsigned long t2;
struct stat st;
char num[64];
char buf[PATH_MAX + 1];
char tmp[PATH_MAX + 1];
static int auth = -1;
messagef((state->id, NiL, -8, "auth(%d,%s,%s) call", fd, path, arg));
if (!path)
{
if (fd < 0)
goto sorry;
if (!getauth(fd, n))
goto ok;
n = sfsprintf(buf, sizeof(buf), "%d\n", CS_KEY_SEND);
if (cswrite(state, fd, buf, n) != n)
{
messagef((state->id, NiL, -1, "auth: `%-.*s': KEY_SEND write error", n - 1, buf));
goto sorry;
}
if ((n = csread(state, fd, buf, sizeof(buf), CS_LINE)) <= 1)
{
messagef((state->id, NiL, -1, "auth: KEY_SEND read error"));
goto sorry;
}
buf[n - 1] = 0;
path = (const char*)buf;
}
if (stat(path, &st))
{
if (errno == ENOENT)
goto ok;
messagef((state->id, NiL, -1, "auth: %s: stat error", path));
return -1;
}
if (fd < 0)
{
/*
* the remote side of remote authentication
*/
fd = 0;
wfd = 1;
}
else wfd = fd;
m = getpid();
s = tmp + sfsprintf(tmp, sizeof(tmp) - 1, "%lu %d", (unsigned long)st.st_mtime, m);
if ((t = (char*)arg) && !(st.st_mode & S_IXOTH))
{
b = tmp + sizeof(tmp) - 1;
if (s < b)
{
*s++ = ' ';
while (s < b && *t)
if ((*s++ = *t++) == '/' && *t == '#' && *++t != '#')
*(s - 1) = ' ';
}
}
*s++ = '\n';
n = s - tmp;
if (cswrite(state, wfd, tmp, n) != n)
{
messagef((state->id, NiL, -1, "auth: `%-.*s': key write error", n - 1, tmp));
goto sorry;
}
if (csread(state, fd, num, sizeof(num), CS_LINE) <= 0)
{
messagef((state->id, NiL, -1, "auth: key read error"));
goto sorry;
}
if (*num != '\n')
{
n = 0;
if (state->addr == csaddr(state, NiL)) b = tmp + sfsprintf(tmp, sizeof(tmp), "%s/AUTH.%05d.", csvar(state, CS_VAR_LOCAL, 0), m);
else
{
s = (char*)path + strlen(path);
while (s > (char*)path)
if (*--s == '/' && ++n >= 4) break;
if (n != 4) goto sorry;
b = tmp + sfsprintf(tmp, sizeof(tmp), "%-.*s/AUTH.%05d.", s - path, path, m);
}
if (s = strrchr(tmp, '/'))
{
*s = 0;
if (eaccess(tmp, X_OK) && (mkdir(tmp, S_IRWXU|S_IRWXG|S_IRWXO) || chmod(tmp, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)))
{
messagef((state->id, NiL, -1, "auth: %s: challenge directory error", tmp));
goto sorry;
}
*s = '/';
}
t1 = CSTIME();
m += t1 + getppid();
t1 -= CS_STAT_DOWN;
if (auth < 0) auth = (unsigned int)CSTOSS(m, 0) % AUTH_BASE;
n = auth;
for (;;)
{
if (++auth >= AUTH_BASE) auth = 0;
if (auth == n)
{
messagef((state->id, NiL, -1, "auth: %s: challenge directory full", tmp));
goto sorry;
}
s = b + sfsprintf(b, sizeof(tmp) - (b - tmp), "%03d", auth);
if ((stat(tmp, &st) || t1 <= (unsigned long)st.st_ctime && !remove(tmp)) && !close(open(tmp, O_CREAT|O_TRUNC|O_cloexec, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) break;
}
key = tmp;
if (tokscan(num, NiL, "%lu %lu", &t1, &t2) != 2)
{
messagef((state->id, NiL, -1, "auth: `%s': challenge syntax error", num));
goto sorry;
}
if (cschallenge(state, tmp, &t1, &t2))
goto sorry;
if (chmod(tmp, S_ISUID|S_ISGID|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))
{
messagef((state->id, NiL, -1, "auth: %s: challenge chmod error", tmp));
goto sorry;
}
t = s;
if (arg)
{
b = tmp + sizeof(tmp) - 1;
if (s < b)
{
*s++ = ' ';
while (s < b && *arg)
if ((*s++ = *arg++) == '/' && *arg == '#')
{
arg++;
*(s - 1) = ' ';
}
}
}
*s++ = '\n';
n = cswrite(state, wfd, tmp, s - tmp);
*t = 0;
if (n != s - tmp)
{
messagef((state->id, NiL, -1, "auth: `%s': ack write error", tmp));
goto sorry;
}
if (csread(state, fd, num, 1, CS_LINE) != 1)
{
messagef((state->id, NiL, -1, "auth: ack read error"));
goto sorry;
}
if (remove(tmp))
{
messagef((state->id, NiL, -1, "auth: %s: challenge remove error", tmp));
goto sorry;
}
}
if (fd >= 0) setauth(fd, n);
ok:
messagef((state->id, NiL, -8, "auth(%d,%s,%s) = 0", fd, path, arg));
return 0;
sorry:
if (key) remove(key);
errno = EACCES;
return -1;
}
/*
* set up the challenge {v1,v2} on path
*/
int
cschallenge(Cs_t* state, const char* path, unsigned long* v1, unsigned long* v2)
{
struct stat st;
if (touch(path, (time_t)(v1 ? *v1 : cs.time), (time_t)(v2 ? *v2 : cs.time), 0))
{
messagef((state->id, NiL, -1, "auth: %s: challenge touch error", path));
return -1;
}
if (stat(path, &st))
{
messagef((state->id, NiL, -1, "auth: %s: challenge stat error", path));
return -1;
}
if (v1)
*v1 = st.st_atime;
if (v2)
*v2 = st.st_mtime;
return 0;
}
int
_cs_auth(int fd, const char* path, const char* arg)
{
return csauth(&cs, fd, path, arg);
}
int
_cs_challenge(const char* path, unsigned long* v1, unsigned long* v2)
{
return cschallenge(&cs, path, v1, v2);
}

View file

@ -1,264 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* internet address/port binding
*/
#include "cslib.h"
/*
* low level for csbind()
*/
static int
portbind(register Cs_t* state, const char* type, unsigned long addr, unsigned int port)
{
#if CS_LIB_V10
int fd;
struct tcpuser tcp;
if (streq(type, "udp"))
{
if (!addr)
{
if ((fd = udp_datagram(port)) < 0)
messagef((state->id, NiL, -1, "bind: %s: udp_datagram error", type));
return fd;
}
if (addr == CS_LOCAL) addr = 0;
if ((fd = udp_connect(0, addr, port)) < 0)
messagef((state->id, NiL, -1, "bind: %s: udp_connect error", type));
return fd;
}
else if (streq(type, "tcp"))
{
if ((fd = tcp_sock()) < 0)
{
messagef((state->id, NiL, -1, "bind: %s: tcp_sock error", type));
return -1;
}
memzero(&tcp, sizeof(tcp));
tcp.fport = port;
if (addr != CS_LOCAL) tcp.faddr = addr;
if (addr ? !tcp_connect(fd, &tcp) : !tcp_listen(fd, &tcp))
{
state->addr = tcp.laddr;
state->port = tcp.lport;
return fd;
}
messagef((state->id, NiL, -1, "bind: %s %s error", type, addr ? "tcp_connect" : "tcp_listen"));
close(fd);
}
#else
#if CS_LIB_SOCKET
int fd;
int sock;
int r;
struct sockaddr_in nam;
Sock_size_t namlen = sizeof(nam);
if (streq(type, "tcp")) sock = SOCK_STREAM;
else if (streq(type, "udp")) sock = SOCK_DGRAM;
else
{
messagef((state->id, NiL, -1, "bind: %s: invalid type", type));
return -1;
}
if ((fd = socket(AF_INET, sock, 0)) < 0)
{
messagef((state->id, NiL, -1, "bind: %s: AF_INET socket error", type));
return -1;
}
memzero(&nam, sizeof(nam));
nam.sin_family = AF_INET;
if (addr != CS_LOCAL) nam.sin_addr.s_addr = addr;
state->addr = addr;
state->port = port;
nam.sin_port = htons(port);
if (addr)
{
#if defined(O_NONBLOCK) || defined(FNDELAY)
int fl;
#endif
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
int sl;
#endif
if (state->flags & CS_ADDR_NOW)
{
#if defined(O_NONBLOCK) || defined(FNDELAY)
if ((fl = fcntl(fd, F_GETFL, 0)) != -1)
#if defined(FNDELAY)
fcntl(fd, F_SETFL, fl|FNDELAY);
#else
fcntl(fd, F_SETFL, fl|O_NONBLOCK);
#endif
#endif
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
if (sock == SOCK_STREAM)
{
sl = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char*)&sl, sizeof(sl));
}
#endif
}
if (!(r = connect(fd, (struct sockaddr*)&nam, sizeof(nam)))
#ifdef EINPROGRESS
|| errno == EINPROGRESS
#endif
)
{
if (!r && (state->flags & CS_ADDR_NOW))
{
#if defined(O_NONBLOCK) || defined(FNDELAY)
if (fl != -1)
fcntl(fd, F_SETFL, fl);
#endif
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
if (sock == SOCK_STREAM)
{
sl = 0;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char*)&sl, sizeof(sl));
}
#endif
}
state->addr = nam.sin_addr.s_addr;
state->port = port;
return fd;
}
messagef((state->id, NiL, -1, "bind: %s: connect error", type));
if (errno == EADDRNOTAVAIL || errno == ECONNREFUSED)
errno = ENOENT;
}
else
{
#ifdef SO_REUSEADDR
if (state->port != CS_PORT_NORMAL)
{
int n = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&n, sizeof(n));
}
#endif
if (!bind(fd, (struct sockaddr*)&nam, sizeof(nam)) && (sock != SOCK_STREAM || !listen(fd, 32)))
{
if (!getsockname(fd, (struct sockaddr*)&nam, &namlen) && namlen == sizeof(nam))
{
state->addr = nam.sin_addr.s_addr;
state->port = ntohs((unsigned short)nam.sin_port);
}
else messagef((state->id, NiL, -1, "bind: %s: getsockname error", type));
return fd;
}
messagef((state->id, NiL, -1, "bind: %s: bind error", type));
if (errno == EADDRINUSE) errno = EEXIST;
}
close(fd);
#else
errno = ENOTDIR;
messagef((state->id, NiL, -1, "bind: %s: not supported", type));
#endif
#endif
return -1;
}
/*
* create [addr==0] or open stream fd for <type,addr,port>
* for create
*
* addr CS_LOCAL for local address
*
* port CS_PORT_NORMAL for normal port allocation
* CS_PORT_RESERVED for reserved port allocation
*/
int
csbind(register Cs_t* state, const char* type, unsigned long addr, unsigned long port, unsigned long clone)
{
int fd;
messagef((state->id, NiL, -8, "bind(%s,%s,%u,%lu) call", type, csntoa(state, addr), port, clone));
if (port == CS_PORT_INVALID)
return -1;
if (port == CS_PORT_RESERVED)
{
static unsigned int last = IPPORT_RESERVED;
if (addr)
{
errno = EROFS;
messagef((state->id, NiL, -1, "bind: %s: explicit reserved port invalid", csntoa(state, addr)));
return -1;
}
port = last;
do
{
if (--last <= IPPORT_RESERVED / 2)
port = IPPORT_RESERVED - 1;
if (last == port)
{
errno = ENOSPC;
messagef((state->id, NiL, -1, "bind: no more reserved ports"));
break;
}
if ((fd = portbind(state, type, 0L, last)) >= 0)
goto ok;
} while (errno != EACCES);
messagef((state->id, NiL, -1, "bind: reserved port allocation error"));
return -1;
}
if (port == CS_PORT_NORMAL && addr)
{
errno = EROFS;
return -1;
}
if ((fd = portbind(state, type, addr, port)) < 0)
return -1;
if (clone)
{
int n;
char buf[16];
n = sfsprintf(buf, sizeof(buf), "%d %lu\n", CS_KEY_CLONE, clone);
cswrite(state, fd, buf, n);
}
ok:
messagef((state->id, NiL, -8, "bind(%s,%s,%u,%lu) = %d", type, csntoa(state, addr), port, clone, fd));
return fd;
}
int
_cs_bind(const char* type, unsigned long addr, unsigned long port, unsigned long clone)
{
return csbind(&cs, type, addr, port, clone);
}

View file

@ -1,201 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* client line by line interaction
*/
#include "cslib.h"
#include "FEATURE/termios"
#if !_lib_tcgetattr || !_lib_tcsetattr
#undef _hdr_termios
#endif
#if _hdr_termios
#include <termios.h>
#endif
#if _hdr_termios
static struct State_s
{
struct termios new_term; /* raw term for -r */
struct termios old_term; /* original term for -r */
} state;
static void
restore(void)
{
tcsetattr(0, TCSANOW, &state.old_term);
}
#endif
/*
* if fd<0 then establish client connection to service
* if argv specified then each is a command line to be executed
* if CS_CLIENT_ARGV not set then additional commands read from stdin
*/
int
csclient(Cs_t* cs, int fd, const char* service, const char* prompt, char** argv, unsigned int flags)
{
register int i;
char* s;
Sfio_t* tmp;
int done;
int promptlen;
int timeout;
ssize_t n;
int sdf[2];
Cspoll_t fds[2];
char buf[8 * 1024];
if (fd < 0 && (fd = csopen(cs, service, CS_OPEN_TEST)) < 0)
{
if (errno == ENOENT)
error(3, "%s: server not running", service);
else
error(ERROR_SYSTEM|3, "%s: cannot open connect stream", service);
}
#if _hdr_termios
if (flags & CS_CLIENT_RAW)
{
tcgetattr(0, &state.old_term);
atexit(restore);
state.new_term = state.old_term;
state.new_term.c_iflag &= ~(BRKINT|IGNPAR|PARMRK|INLCR|IGNCR|ICRNL);
state.new_term.c_lflag &= ~(ECHO|ECHOK|ICANON|ISIG);
state.new_term.c_cc[VTIME] = 0;
state.new_term.c_cc[VMIN] = 1;
tcsetattr(0, TCSANOW, &state.new_term);
}
#endif
sdf[0] = fd;
sdf[1] = 1;
if (argv && *argv)
{
fds[0].fd = 1;
fds[0].events = CS_POLL_WRITE;
}
else
{
argv = 0;
fds[0].fd = 0;
fds[0].events = CS_POLL_READ;
}
fds[1].fd = fd;
fds[1].events = CS_POLL_READ;
done = 0;
if (promptlen = (!argv && prompt && isatty(fds[0].fd) && isatty(1)) ? strlen(prompt) : 0)
write(1, prompt, promptlen);
timeout = CS_NEVER;
tmp = 0;
while (cspoll(cs, fds, elementsof(fds), timeout) > 0)
for (i = 0; i < elementsof(fds); i++)
if (fds[i].status & (CS_POLL_READ|CS_POLL_WRITE))
{
if (!i && argv)
{
if (!*argv)
{
argv = 0;
fds[0].fd = 0;
if (flags & CS_CLIENT_ARGV)
{
if (done++)
return 0;
timeout = 500;
}
fds[0].events = CS_POLL_READ;
continue;
}
if (!tmp && !(tmp = sfstropen()))
error(ERROR_SYSTEM|3, "out of space");
for (;;)
{
s = *argv++;
if ((flags & CS_CLIENT_SEP) && *s == ':' && !*(s + 1))
break;
if (sfstrtell(tmp))
sfputc(tmp, ' ');
sfprintf(tmp, "%s", s);
if (!(flags & CS_CLIENT_SEP) || !*argv)
break;
}
sfputc(tmp, '\n');
n = sfstrtell(tmp);
s = sfstruse(tmp);
}
else if ((n = read(fds[i].fd, s = buf, sizeof(buf) - 1)) < 0)
error(ERROR_SYSTEM|3, "/dev/fd/%d: read error", fds[i].fd);
if (!n)
{
if (done++)
return 0;
if (!i)
write(sdf[i], "quit\n", 5);
continue;
}
if (!i)
{
#if _hdr_termios
register char* u;
register int m;
s[n] = 0;
if ((u = strchr(s, 035)))
{
if ((m = u - s) > 0 && write(sdf[i], s, m) != m)
error(ERROR_SYSTEM|3, "/dev/fd/%d: write error", sdf[i]);
tcsetattr(0, TCSANOW, &state.old_term);
if (promptlen)
write(1, prompt, promptlen);
if ((n = read(fds[i].fd, s = buf, sizeof(buf) - 1)) <= 0)
{
write(1, "\n", 1);
return 0;
}
buf[n - 1] = 0;
if (*u == 'q' || *u == 'Q')
return 0;
tcsetattr(0, TCSANOW, &state.new_term);
if (*u)
error(1, "%s: unknown command", u);
continue;
}
#endif
}
if (write(sdf[i], s, n) != n)
error(ERROR_SYSTEM|3, "/dev/fd/%d: write error", sdf[i]);
if (sdf[i] == 1 && promptlen)
write(1, prompt, promptlen);
}
return error_info.errors != 0;
}
int
_cs_client(int fd, const char* service, const char* prompt, char** argv, unsigned int flags)
{
return csclient(&cs, fd, service, prompt, argv, flags);
}

View file

@ -1,51 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* output control mark on fd
*/
#include "cslib.h"
int
cscontrol(register Cs_t* state, int fd)
{
#if CS_LIB_SOCKET
return send(fd, "", 1, MSG_OOB) == 1 ? 0 : -1;
#else
#if CS_LIB_STREAM
struct strbuf buf;
buf.maxlen = 0;
return putmsg(fd, NiL, &buf, RS_HIPRI);
#else
return write(fd, "", 1) == 1 ? 0 : -1;
#endif
#endif
}
int
_cs_control(int fd)
{
return cscontrol(&cs, fd);
}

View file

@ -1,144 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* slip into the background
* (1<<fd) bits not in fds will be modified:
* 0-2 dup'd to /dev/null
* 3-sysconf(_SC_OPEN_MAX) closed
*
* daemon details thanks to
* "UNIX Network Programming, W. Richard Stevens, Prentice Hall, 1990"
*/
#include "cslib.h"
#include <sig.h>
int
csdaemon(register Cs_t* state, int fds)
{
register int fd;
register int i;
int oerrno;
messagef((state->id, NiL, -8, "daemon(%o) call", fds));
oerrno = errno;
/*
* unconditionally ignore some signals
*/
signal(SIGHUP, SIG_IGN);
#ifdef SIGTTOU
signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
#endif
/*
* generate some children if not scheduled from init
*/
if (getppid() > 1)
{
#if _lib_fork
if (!(state->flags & CS_DAEMON_SLAVE)) switch (fork())
{
case -1:
return -1;
case 0:
systrace(NiL);
break;
default:
/*
* allow some time for service setup
*/
sleep(2);
exit(0);
}
#endif
/*
* become process group leader and drop control tty
*/
setsid();
}
/*
* redirect {0,1,2} to /dev/null if not in fds
*/
if ((fds & ((1<<0)|(1<<1)|(1<<2))) != ((1<<0)|(1<<1)|(1<<2)) && (fd = open("/dev/null", O_RDWR)) >= 0)
{
fds |= (1<<fd);
for (i = 0; i <= 2; i++)
if (!(fds & (1<<i)))
{
close(i);
dup(fd);
}
close(fd);
}
/*
* close any other garbage fds
*/
for (i = 3; i < 20; i++)
if (!(fds & (1<<i)) && !fcntl(i, F_GETFD, 0))
close(i);
/*
* avoid unexpected permission problems
*/
umask(0);
/*
* no command-relative relative root searching
*/
pathpath(NiL, "", 0, NiL, 0);
/*
* we ignored a lot of errors to get here
*/
errno = oerrno;
messagef((state->id, NiL, -8, "daemon(%o) = 0", fds));
return 0;
}
int
_cs_daemon(int fds)
{
return csdaemon(&cs, fds);
}

View file

@ -1,37 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
/*
* Glenn Fowler
* AT&T Research
*
* cs library data
*/
static char id_cs[] = "\n@(#)$Id: libcs (AT&T Research) 2001-12-12 $\0\n";
#include "cslib.h"
static Csdisc_t disc = { CS_VERSION };
Cs_t cs = { "libcs:cs", &disc };
#ifdef NoF
NoF(csdata)
#endif

View file

@ -1,37 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* free cs state context
*/
#include "cslib.h"
int
csfree(register Cs_t* state)
{
if (!state || state == &cs)
return -1;
free(state);
return 0;
}

View file

@ -1,92 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* read datagram
*/
#include "cslib.h"
ssize_t
csfrom(register Cs_t* state, int fd, void* buf, size_t siz, Csaddr_t* addr)
{
#if CS_LIB_V10
ssize_t n;
struct udpaddr udp;
if (read(fd, &udp, sizeof(udp)) != sizeof(udp))
{
messagef((state->id, NiL, -1, "from: %d: udp header read error", fd));
return -1;
}
if (addr)
{
addr->addr[0] = udp.host;
addr->addr[1] = udp.port;
addr->addr[2] = 0;
}
if ((n = read(fd, buf, siz)) < 0) messagef((state->id, NiL, -1, "from: %d: udp data read error", fd));
else messagef((state->id, NiL, -8, "from(%d,*,%d) = %d, data = `%-.*s', addr = %s, port = %u", fd, siz, n, n, buf, csntoa(state, udp.host), udp.port));
return n;
#else
#if CS_LIB_SOCKET
ssize_t n;
Sock_size_t len;
struct sockaddr_in nam;
len = sizeof(nam);
if ((n = recvfrom(fd, buf, siz, 0, (struct sockaddr*)&nam, &len)) < 0)
{
messagef((state->id, NiL, -1, "from: %d: recvfrom error", fd));
return -1;
}
if (addr)
{
addr->addr[0] = (unsigned long)nam.sin_addr.s_addr;
addr->addr[1] = (unsigned long)nam.sin_port;
}
messagef((state->id, NiL, -8, "from(%d,*,%d) = %d, data = `%-.*s', addr = %s, port = %u", fd, siz, n, n, buf, csntoa(state, (unsigned long)nam.sin_addr.s_addr), (unsigned long)nam.sin_port));
return n;
#else
errno = EINVAL;
messagef((state->id, NiL, -1, "from: %d: udp read not supported", fd));
return -1;
#endif
#endif
}
ssize_t
_cs_from(int fd, void* buf, size_t siz, Csaddr_t* addr)
{
return csfrom(&cs, fd, buf, siz, addr);
}

View file

@ -1,46 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* like csname() except `.' qualifications retained
*/
#include "cslib.h"
char*
csfull(register Cs_t* state, unsigned long addr)
{
char* s;
state->flags |= CS_ADDR_FULL;
s = csname(state, addr);
state->flags &= ~CS_ADDR_FULL;
messagef((state->id, NiL, -8, "full(%s) = %s", csntoa(state, addr), s));
return s;
}
char*
_cs_full(unsigned long addr)
{
return csfull(&cs, addr);
}

View file

@ -1,61 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return Sfio_t stream pointer to host info file
* if line!=0 then it points to current line number in file
*/
#include "cslib.h"
Sfio_t*
csinfo(register Cs_t* state, const char* file, int* line)
{
int n;
Sfio_t* sp = 0;
char buf[PATH_MAX];
char tmp[PATH_MAX];
struct stat st;
messagef((state->id, NiL, -8, "info(%s) call", file));
if (!file || streq(file, "-")) file = CS_SVC_INFO;
if (strmatch(file, "*[ \t\n=]*")) sp = tokline(file, SF_STRING, line);
else if (!strchr(file, '/') || stat(file, &st) || S_ISDIR(st.st_mode) || !(sp = tokline(file, SF_READ, line)))
for (n = 0; n <= 1; n++)
{
sfsprintf(tmp, sizeof(tmp), "%s/%s", n ? csvar(state, CS_VAR_SHARE, 0) : CS_SVC_DIR, file);
if (pathpath(tmp, "", PATH_REGULAR|PATH_READ, buf, sizeof(buf)))
{
sp = tokline(buf, SF_READ, line);
break;
}
}
if (!sp) messagef((state->id, NiL, -1, "info: %s: not found", file));
return sp;
}
Sfio_t*
_cs_info(const char* file, int* line)
{
return csinfo(&cs, file, line);
}

View file

@ -1,226 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* connect stream library implementation definitions
*/
#ifndef _CSLIB_H
#define _CSLIB_H
#define CS_INTERFACE 2 /* thread safe Cs_t* 1st arg */
#define CS_AUTH_MASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
#define CS_AUTH_MODE (S_ISUID|S_ISGID|S_IRUSR)
typedef struct
{
unsigned long addr;
unsigned long port;
} Inet_t;
struct Server_s;
typedef struct Server_s Server_t;
#define _CS_PRIVATE_ \
Inet_t proxy; /* proxy inet addr.port */ \
int db; /* csdb() state */ \
int interrupt; /* last interrupt */ \
int nostream; /* cspeek() state */ \
int nosocket; /* cspeek() state */ \
Server_t* server; /* csserve() state */ \
char full[4 * CS_NAME_MAX]; /* csname() full buffer */ \
char name[CS_NAME_MAX]; /* csname() short buffer */ \
char ntoa[16]; /* csntoa() buffer */ \
char path[PATH_MAX]; /* lib work buffer */ \
char temp[CS_NAME_MAX];/* lib work buffer */
#include <cs.h>
#include <debug.h>
#include <errno.h>
#include <sig.h>
#include <tok.h>
#include <ast_tty.h>
#include <cs_lib.h>
#if CS_LIB_V10
#include <sys/filio.h>
#include <sys/inio.h>
#include <sys/inet/in.h>
#include <sys/inet/tcp_user.h>
#define I_ACCEPT FIOACCEPT
#define I_RECVFD FIORCVFD
#define I_SENDFD FIOSNDFD
#define FDARG(f) (&(f))
#define strrecvfd passfd
extern int conn_ld;
#else
#if CS_LIB_SOCKET
#include <sys/socket.h>
#if CS_LIB_SOCKET_UN
#if _sys_sockio
#include <sys/sockio.h>
#else
#include <sys/ioctl.h>
#endif
#if _sys_uio && !defined(MAX_IOVEC)
#include <sys/uio.h>
#endif
#if _sys_un
#include <sys/un.h>
#endif
#endif
#if _hdr_netinet_in
#include <netinet/in.h>
#endif
#if _hdr_netinet_tcp
#include <netinet/tcp.h>
#endif
#if _hdr_netdb
#include <netdb.h>
#endif
#endif
#if CS_LIB_STREAM
#include <stropts.h>
#define FDARG(f) (f)
#endif
#endif
#if CS_LIB_STREAM || CS_LIB_V10
struct csfdhdr /* send/recv fd data header */
{
long count;
long pid;
};
#endif
#ifndef IPPORT_RESERVED
#define IPPORT_RESERVED 1024
#endif
#ifndef IPPORT_USERRESERVED
#define IPPORT_USERRESERVED 5000
#endif
#if !defined(htons) && !_lib_htons
#define htons(x) (x)
#endif
#if !defined(htonl) && !_lib_htonl
#define htonl(x) (x)
#endif
#if !defined(ntohs) && !_lib_ntohs
#define ntohs(x) (x)
#endif
#if !defined(ntohl) && !_lib_ntohl
#define ntohl(x) (x)
#endif
#if defined(F_GETFL) && defined(F_SETFL)
#if !defined(FAPPEND)
#if _sys_file
#include <sys/file.h>
#endif
#if !defined(FAPPEND) && defined(O_APPEND)
#define FAPPEND O_APPEND
#endif
#endif
#endif
#if defined(F_GETFL) && defined(F_SETFL) && defined(FAPPEND)
#define setauth(f,t) ((t=fcntl(f,F_GETFL,0))>=0&&fcntl(f,F_SETFL,t|FAPPEND)>=0)
#define getauth(f,t) ((t=fcntl(f,F_GETFL,0))>=0&&(t&FAPPEND))
#else
#define setauth(f,t) (0)
#define getauth(f,t) (0)
#endif
#if !defined(SIGCHLD) && defined(SIGCLD)
#define SIGCHLD SIGCLD
#endif
#ifdef SIGPIPE
#if _lib_sigblock
#define csprotect(h) do if (!((h)->flags & CS_PIPE_BLOCKED)) { (h)->flags |= CS_PIPE_BLOCKED; sigblock(sigmask(SIGPIPE)); errorf((h)->id, NiL, -99, "protect"); } while (0)
#else
#define csprotect(h) do if (!((h)->flags & CS_PIPE_BLOCKED)) { Handler_t f; (h)->flags |= CS_PIPE_BLOCKED; if ((f = signal(SIGPIPE, SIG_IGN)) != SIG_DFL) signal(SIGPIPE, f); errorf((h)->id, NiL, -99, "protect"); } while (0)
#endif
#else
#define csprotect(h) do if (!((h)->flags & CS_PIPE_BLOCKED)) { (h)->flags |= CS_PIPE_BLOCKED; errorf((h)->id, NiL, -99, "protect"); } while (0)
#endif
#define CS_SVC_INET "inet."
#define CS_PROC_FD_TST "/proc/self/fd/."
#define CS_PROC_FD_FMT "/proc/%lu/fd/%u"
#define CS_KEY_SEND 0
#define CS_KEY_CLONE 1
#define CS_KEY_MAX 9
#ifndef ENOTDIR
#define ENOTDIR ENOENT
#endif
#ifndef EROFS
#define EROFS EACCES
#endif
#ifndef errno
extern int errno;
#endif
#if CS_LIB_SOCKET
#define csdb(h) do{if((h)->db<=0)cssetdb(h);}while(0)
#else
#define csdb(h)
#endif
#define cssetdb _cs_setdb
extern void cssetdb(Cs_t*);
#if CS_LIB_V10
extern int fmount(int, int, const char*, int);
#endif
#if CS_LIB_STREAM
extern int fattach(int, const char*);
#endif
#endif

View file

@ -1,226 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* open|initiate /dev/fdp/local/<service>/user
* coded for bootstrap
*/
#include "cslib.h"
#include <wait.h>
#define DEVLOCAL "/dev/fdp/local/"
#ifdef SIGCHLD
static int children;
static void
child(int sig)
{
NoP(sig);
children++;
}
#endif
static int
initiate(Cs_t* state, const char* svc, char* cmd)
{
pid_t pid;
pid_t n;
char* av[3];
#ifdef SIGCHLD
Handler_t fun;
children = 0;
if ((fun = signal(SIGCHLD, child)) == SIG_DFL) signal(SIGCHLD, fun);
else if (children) children++;
#endif
pathcanon(cmd, 0, 0);
av[0] = cmd;
av[1] = (char*)svc;
av[2] = 0;
if ((pid = spawnveg(av[0], av, environ, 0)) == -1)
{
messagef((state->id, NiL, -1, "local: %s: cannot initiate %s", svc, cmd));
return -1;
}
while ((n = waitpid(pid, NiL, 0)) == -1 && errno == EINTR);
#ifdef SIGCHLD
if (fun != SIG_DFL)
{
signal(SIGCHLD, fun);
if (fun != SIG_IGN)
while (--children > 0)
(*fun)(SIGCHLD);
}
#endif
/*
* yuk: looks like we have to give fdp services time
* to start up -- a few seconds shouldn't hurt
*/
sleep(2);
return n;
}
int
cslocal(register Cs_t* state, const char* path)
{
register char* s;
register char* p;
register char* t;
register char* v;
struct stat st;
char cmd[PATH_MAX / 8];
char exe[PATH_MAX + 1];
char tmp[PATH_MAX + 1];
#if CS_LIB_STREAM || CS_LIB_V10 || CS_LIB_SOCKET_UN
int fd;
int n;
#endif
messagef((state->id, NiL, -8, "local(%s) call", path));
/*
* validate the path
*/
p = (char*)path;
if (strncmp(p, DEVLOCAL, sizeof(DEVLOCAL) - 1))
{
messagef((state->id, NiL, -1, "local: %s: %s* expected", path, DEVLOCAL));
goto sorry;
}
p += sizeof(DEVLOCAL) - 1;
for (t = p; *t && *t != '/'; t++);
if (!streq(t + 1, "user"))
{
messagef((state->id, NiL, -1, "local: %s: %s*/user expected", path, DEVLOCAL));
goto sorry;
}
/*
* locate the service
*/
s = cmd;
for (v = p; p <= t; *s++ = *p++);
t = s - 1;
for (p = v; p <= t; *s++ = *p++);
for (p = CS_SVC_SUFFIX; *s++ = *p++;);
p = pathbin();
for (;;)
{
p = pathcat(p, ':', "../lib/cs/fdp", cmd, exe, PATH_MAX + 1);
if (!eaccess(exe, X_OK) && !stat(exe, &st)) break;
if (!p)
{
messagef((state->id, NiL, -1, "local: %s: %s: cannot locate service on ../lib/cs/fdp", path, cmd));
goto sorry;
}
}
*t = 0;
sfsprintf(tmp, sizeof(tmp), "%s/fdp/%s/%s/%d-%d-/%c%s", csvar(state, CS_VAR_LOCAL, 0), csname(state, 0), cmd, st.st_uid, geteuid(), CS_MNT_STREAM, CS_MNT_TAIL);
#if CS_LIB_STREAM || CS_LIB_V10
for (n = 0; (fd = open(tmp, O_RDWR)) < 0; n++)
if (n || errno == EACCES)
{
messagef((state->id, NiL, -1, "local: %s: %s: cannot open service", path, tmp));
return -1;
}
else if (initiate(state, path, exe) < 0)
{
messagef((state->id, NiL, -1, "local: %s: %s: cannot initiate service %s", path, tmp, exe));
return -1;
}
messagef((state->id, NiL, -8, "local(%s) fd=%d server=%s stream=%s", path, fd, exe, tmp));
return fd;
#else
#if CS_LIB_SOCKET_UN
{
int namlen;
struct sockaddr_un nam;
nam.sun_family = AF_UNIX;
strcpy(nam.sun_path, tmp);
namlen = sizeof(nam.sun_family) + strlen(tmp);
n = 0;
fd = -1;
for (;;)
{
if (fd < 0 && (fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
messagef((state->id, NiL, -1, "local: %s: AF_UNIX socket error", path));
return -1;
}
if (!connect(fd, (struct sockaddr*)&nam, namlen))
{
#if CS_LIB_SOCKET_RIGHTS
if (read(fd, cmd, 1) != 1)
messagef((state->id, NiL, -1, "local: %s: connect ack read error", path));
else if (cssend(state, fd, NiL, 0))
messagef((state->id, NiL, -1, "local: %s: connect authentication send error", path));
else
#endif
return fd;
#if CS_LIB_SOCKET_RIGHTS
close(fd);
fd = -1;
#endif
}
else messagef((state->id, NiL, -1, "local: %s: connect error", path));
if (errno != EACCES) errno = ENOENT;
if (n || errno == EACCES || initiate(state, path, exe) < 0)
{
if (fd >= 0) close(fd);
return -1;
}
n = 1;
messagef((state->id, NiL, -1, "local: %s: connect retry", path));
}
}
#endif
#endif
sorry:
errno = ENOENT;
return -1;
}
int
_cs_local(const char* path)
{
return cslocal(&cs, path);
}

View file

@ -1,183 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return host name given address
* if addr==0 then permanent pointer to local host name returned
* otherwise temporary pointer returned
* `.' qualification deleted if possible
*/
#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:hide gethostname
#else
#define gethostname ______gethostname
#endif
#include "cslib.h"
#if _lib_uname && _sys_utsname
#include <sys/utsname.h>
#endif
#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:nohide gethostname
#else
#undef gethostname
#endif
#if _lib_gethostname
extern int gethostname(char*, size_t);
#endif
#if !CS_LIB_LOCAL && CS_LIB_SOCKET
/*
* keep host db connection alive
* the lib should make hidden fd's close-on-exec
*/
void
cssetdb(register Cs_t* state)
{
register int fd;
register int i;
if (state->db <= 0 && ++state->db)
{
if ((fd = dup(0)) >= 0)
close(fd);
sethostent(1);
gethostbyname("localhost");
if (fd >= 0)
for (i = fd; i < fd + 3 && fcntl(i, F_SETFD, FD_CLOEXEC) < 0; i++);
}
}
#endif
/*
* return host name for addr
*/
char*
csname(register Cs_t* state, unsigned long addr)
{
register char* s;
messagef((state->id, NiL, -8, "name(%s) call", csntoa(state, addr)));
#if CS_LIB_LOCAL
NoP(addr);
#else
if (addr)
{
if (addr != CS_LOCAL)
{
#if CS_LIB_SOCKET
struct hostent* hp;
struct in_addr ha;
#endif
csdb(state);
#if CS_LIB_SOCKET || CS_LIB_V10
#if CS_LIB_SOCKET
ha.s_addr = addr;
if ((hp = gethostbyaddr((char*)&ha, sizeof(ha), AF_INET)) && (s = hp->h_name))
#else
if (s = in_host(addr))
#endif
{
if (!((state->flags | state->disc->flags) & CS_ADDR_FULL))
{
register char* t;
if ((t = strrchr(s, '.')) && !*(t + 1)) *t = 0;
if (t = strchr(s, '.'))
{
strncpy(state->temp, s, sizeof(state->temp) - 1);
*(t = state->temp + (t - s)) = 0;
s = state->temp;
if (csaddr(state, s) != addr) *t = '.';
}
}
return s;
}
#endif
messagef((state->id, NiL, -1, "name: %s: gethostbyaddr error", csntoa(state, addr)));
s = csntoa(state, addr);
return s;
}
}
#endif
if (!state->name[0])
{
#if _lib_gethostname
if (gethostname(state->full, sizeof(state->full) - 1))
#else
#if _lib_uname && _sys_utsname
struct utsname un;
/*
* NOTE: uname(2) may return >0 on success -- go ask your dad
*/
if (uname(&un) >= 0) strncpy(state->full, un.nodename, sizeof(state->full) - 1);
else
#else
int fd;
int n;
if ((fd = open("/etc/whoami", O_RDONLY)) >= 0)
{
if ((n = read(fd, state->full, sizeof(state->full))) > 0) state->full[n - 1] = 0;
close(fd);
}
else
#endif
#endif
{
messagef((state->id, NiL, -1, "name: %s: gethostname error", csntoa(state, addr)));
strcpy(state->full, CS_HOST_LOCAL);
}
state->full[sizeof(state->full) - 1] = 0;
strncpy(state->name, state->full, sizeof(state->name) - 1);
if (s = strchr(state->name, '.')) *s = 0;
}
return ((state->flags | state->disc->flags) & CS_ADDR_FULL) ? state->full : state->name;
}
char*
_cs_name(unsigned long addr)
{
return csname(&cs, addr);
}

View file

@ -1,84 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* note host status change for name
* this is the daemon side of csstat()
*
* NOTE: name must already exist and pwd must be CS_STAT_DIR
*/
#include "cslib.h"
/*
* encode 4 byte int into 2 bytes
*/
static unsigned short
encode(register unsigned long n)
{
register int e;
e = 0;
while (n > 03777)
{
n >>= 1;
e++;
}
return n | (e << 11);
}
int
csnote(register Cs_t* state, const char* name, register Csstat_t* sp)
{
unsigned long idle;
long up;
if (sp->up < 0)
{
idle = -sp->up;
up = 0;
}
else
{
idle = sp->idle;
up = sp->up;
}
#if 0
{
unsigned long a;
unsigned long m;
a = (encode(up) << 16) | encode(idle);
m = (((sp->load >> 3) & 0377) << 24) | ((sp->pctsys & 0377) << 16) | ((sp->pctusr & 0377) << 8) | (sp->users & 0377);
error(-1, "csnote: <%lu,%lu> load=%lu:%lu pctsys=%lu:%lu pctusr=%lu:%lu users=%lu:%lu idle=%lu:%lu", sp->load, ((m >> 24) & 0xff) << 3, sp->pctsys, (m >> 16) & 0xff, sp->pctusr, (m >> 8) & 0xff, sp->users, m & 0xff, sp->idle, sp->users ? ((a & 0x7ff) << ((a >> 11) & 0x1f)) : ~0, a, m);
}
#endif
return touch(name, (encode(up) << 16) | encode(idle), (((sp->load >> 3) & 0377) << 24) | ((sp->pctsys & 0377) << 16) | ((sp->pctusr & 0377) << 8) | (sp->users & 0377), -1);
}
int
_cs_note(const char* name, Csstat_t* sp)
{
return csnote(&cs, name, sp);
}

View file

@ -1,53 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return the string representation of addr
*/
#include "cslib.h"
char*
csntoa(register Cs_t* state, unsigned long addr)
{
register unsigned char* p;
int32_t a;
a = addr;
p = (unsigned char*)&a;
if ((!addr || p[0] == 127 && p[1] == 0 && p[2] == 0 && p[3] <= 1) && !state->ntoa[sizeof(state->ntoa)-1])
{
state->ntoa[sizeof(state->ntoa)-1] = 1;
addr = csaddr(state, NiL);
state->ntoa[sizeof(state->ntoa)-1] = 0;
}
sfsprintf(state->ntoa, sizeof(state->ntoa), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
messagef((state->id, NiL, -8, "ntoa(%s) call", state->ntoa));
return state->ntoa;
}
char*
_cs_ntoa(unsigned long addr)
{
return csntoa(&cs, addr);
}

File diff suppressed because it is too large Load diff

View file

@ -1,202 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return a pointer to a pathname for an open fd
*/
#include "cslib.h"
#include <ast_dir.h>
/*
* someone thinks FIFO and SOCK are the same (bsd, eh?)
*/
#if defined(S_IFMT) && defined(S_IFIFO)
#undef S_ISFIFO
#define S_ISFIFO(m) (((m)&S_IFMT)==S_IFIFO)
#endif
/*
* scan /dev for path matching st
*/
static char*
devpath(char* path, int size, int blk, register struct stat* st)
{
register DIR* dirp;
register struct dirent* entry;
DIR* subp = 0;
char* base;
int n;
int t;
struct stat tst;
strcpy(path, "/dev");
if (!(dirp = opendir(path))) return 0;
path[4] = '/';
base = path + 5;
for (n = 1;;)
{
while (entry = readdir(dirp))
{
#ifdef D_FILENO
if (n && D_FILENO(entry) != st->st_ino)
continue;
#endif
if (*entry->d_name == '.' || D_NAMLEN(entry) + (base - path) + 1 > size)
continue;
strcpy(base, entry->d_name);
if (stat(path, &tst))
continue;
if (!subp && S_ISDIR(tst.st_mode) && !streq(path, "/dev/fd"))
{
subp = dirp;
if (dirp = opendir(path))
{
base = path + strlen(path);
*base++ = '/';
}
else
{
dirp = subp;
subp = 0;
}
continue;
}
#ifndef D_FILENO
if (n && tst.st_ino != st->st_ino)
continue;
#endif
if (idevice(&tst) == idevice(st) && ((t = S_ISBLK(tst.st_mode)) || S_ISCHR(tst.st_mode)) && t == blk && (!n || tst.st_dev == st->st_dev && tst.st_ino == st->st_ino))
{
closedir(dirp);
if (subp) closedir(subp);
return path;
}
}
if (subp)
{
closedir(dirp);
dirp = subp;
subp = 0;
base = path + 5;
}
else if (!n--) break;
else rewinddir(dirp);
}
closedir(dirp);
return 0;
}
/*
* return a pointer to a pathname for an open fd
*/
char*
cspath(register Cs_t* state, register int fd, int flags)
{
register char* s;
char num[16];
struct stat st;
int typ;
#if CS_LIB_V10
struct tcpuser tcp;
#else
#if CS_LIB_SOCKET
struct sockaddr_in lcl;
struct sockaddr_in rmt;
Sock_size_t namlen = sizeof(lcl);
#ifdef SO_TYPE
Sock_size_t typlen = sizeof(typ);
#endif
#endif
#endif
if (fstat(fd, &st)) return "/dev/fd/-1";
else if (S_ISFIFO(st.st_mode)) sfsprintf(state->path, sizeof(state->path), "/dev/pipe/%u", st.st_ino);
#if CS_LIB_V10
else if (!ioctl(fd, TCPGETADDR, &tcp))
{
if (tcp.raddr) sfsprintf(state->path, sizeof(state->path), "/dev/tcp/%s/%d.%d", (flags & CS_PATH_NAME) ? csname(state, tcp.raddr) : csntoa(state, tcp.raddr), ntohs(tcp.rport), ntohs(tcp.lport));
else
{
if (!tcp.laddr) tcp.laddr = csaddr(state, NiL);
sfsprintf(state->path, sizeof(state->path), "/dev/tcp/%s/%d", (flags & CS_PATH_NAME) ? csname(state, tcp.laddr) : csntoa(state, tcp.laddr), ntohs(tcp.lport));
}
}
#endif
#if CS_LIB_SOCKET
else if (!getsockname(fd, (struct sockaddr*)&lcl, &namlen) && namlen == sizeof(lcl) && lcl.sin_family == AF_INET)
{
s = "tcp";
#ifdef SO_TYPE
if (!getsockopt(fd, SOL_SOCKET, SO_TYPE, (char*)&typ, &typlen)) switch (typ)
{
case SOCK_DGRAM:
s = "udp";
break;
case SOCK_STREAM:
break;
default:
sfsprintf(s = num, sizeof(num), "%d.p", typ);
break;
}
#endif
namlen = sizeof(rmt);
if (!getpeername(fd, (struct sockaddr*)&rmt, &namlen) && namlen == sizeof(rmt) && rmt.sin_family == AF_INET)
{
if (!rmt.sin_addr.s_addr) rmt.sin_addr.s_addr = csaddr(state, NiL);
sfsprintf(state->path, sizeof(state->path), "/dev/%s/%s/%d.%d", s, (flags & CS_PATH_NAME) ? csname(state, (unsigned long)rmt.sin_addr.s_addr) : csntoa(state, (unsigned long)rmt.sin_addr.s_addr), ntohs((unsigned short)rmt.sin_port), ntohs((unsigned short)lcl.sin_port));
}
else
{
if (!lcl.sin_addr.s_addr) lcl.sin_addr.s_addr = csaddr(state, NiL);
sfsprintf(state->path, sizeof(state->path), "/dev/%s/%s/%d", s, (flags & CS_PATH_NAME) ? csname(state, (unsigned long)lcl.sin_addr.s_addr) : csntoa(state, (unsigned long)lcl.sin_addr.s_addr), ntohs((unsigned short)lcl.sin_port));
}
}
#endif
else if ((typ = S_ISBLK(st.st_mode)) || S_ISCHR(st.st_mode))
{
if (s = devpath(state->path, sizeof(state->path), typ, &st))
return s;
sfsprintf(state->path, sizeof(state->path), "/dev/%s-%u,%u", typ ? "blk" : "chr", major(idevice(&st)), minor(idevice(&st)));
}
else
sfsprintf(state->path, sizeof(state->path), "/dev/ino/%u/%u", st.st_dev, st.st_ino);
return state->path;
}
char*
_cs_path(int fd, int flags)
{
return cspath(&cs, fd, flags);
}

View file

@ -1,98 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
#include "cslib.h"
#if _socket_peek && !CS_LIB_SOCKET
#include <sys/socket.h>
#endif
#if _stream_peek && !CS_LIB_STREAM
#include <stropts.h>
#endif
/*
* peek up to siz chars from fd into buf
* -1 returned if fd not peekable
*
* NOTE: cspeek() caches the peek state of fd
* call cspeek(-1,...) to flush the cache
*/
ssize_t
cspeek(register Cs_t* state, int fd, void* buf, size_t siz)
{
register int n;
#if _stream_peek
struct strpeek pk;
#endif
if (fd == -1)
{
#if _stream_peek
state->nostream = -1;
#endif
#if _socket_peek
state->nosocket = -1;
#endif
return -1;
}
#if _stream_peek
if (fd != state->nostream)
{
pk.flags = 0;
pk.ctlbuf.maxlen = -1;
pk.ctlbuf.len = 0;
pk.ctlbuf.buf = 0;
pk.databuf.maxlen = siz;
pk.databuf.buf = (char*)buf;
pk.databuf.len = 0;
if ((n = ioctl(fd, I_PEEK, &pk)) >= 0)
{
state->nostream = -1;
if (n > 0) n = pk.databuf.len;
return n;
}
messagef((state->id, NiL, -1, "peek: %d: ioctl I_PEEK error", fd));
state->nostream = fd;
}
#endif
#if _socket_peek
if (fd != state->nosocket)
{
if ((n = recv(fd, (char*)buf, siz, MSG_PEEK)) >= 0)
{
state->nosocket = -1;
return n;
}
messagef((state->id, NiL, -1, "peek: %d: recv MSG_PEEK error", fd));
state->nosocket = fd;
}
#endif
messagef((state->id, NiL, -1, "peek: %d: no peek", fd));
return -1;
}
ssize_t
_cs_peek(int fd, void* buf, size_t siz)
{
return cspeek(&cs, fd, buf, siz);
}

View file

@ -1,51 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* ping host by name
*/
#include "cslib.h"
#define M "yo\n"
#define N (sizeof(M)-1)
int
csping(register Cs_t* state, const char* name)
{
register int fd;
register int n;
sfsprintf(state->temp, sizeof(state->path), "/dev/tcp/%s/inet.echo", name);
if ((fd = csopen(state, state->temp, 0)) < 0) return -1;
n = (cswrite(state, fd, M, N) != N || csread(state, fd, state->temp, N, CS_LINE) != N || strncmp(M, state->temp, N)) ? -1 : 0;
close(fd);
if (n) messagef((state->id, NiL, -1, "ping: %s: no contact", name));
return n;
}
int
_cs_ping(const char* name)
{
return csping(&cs, name);
}

View file

@ -1,52 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* create bi-directional local pipe
*/
#include "cslib.h"
int
cspipe(Cs_t* state, int* fds)
{
csprotect(&cs);
#if CS_LIB_SOCKET_UN
return socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
#else
return pipe(fds);
#endif
}
int
_cs_pipe(int* fds)
{
return cspipe(&cs, fds);
}

View file

@ -1,207 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* poll for read/write/control on fds with ms timeout
* number of selected fd's returned
*/
#include "cslib.h"
#ifdef POLLIST
#undef CS_LIB_SOCKET
#undef CS_LIB_STREAM
#undef CS_LIB_V10
#undef _sys_select
#define CS_LIB_STREAM 1
#endif
#if _sys_select && !defined(FD_SET)
#include <sys/select.h>
#endif
int
cspoll(Cs_t* state, Cspoll_t* fds, int num, int ms)
{
register Cspoll_t* pp;
register Cspoll_t* mp;
#if CS_LIB_SOCKET || CS_LIB_V10
register int events;
register int width;
fd_set rd;
register fd_set* rp = &rd;
fd_set wr;
register fd_set* wp = &wr;
#if CS_LIB_SOCKET
fd_set ex;
register fd_set* ep = &ex;
struct timeval* tp;
struct timeval tv;
if (ms >= 0)
{
tv.tv_sec = ms / 1000;
tv.tv_usec = (ms % 1000) * 1000;
tp = &tv;
}
else tp = 0;
FD_ZERO(ep);
#endif
FD_ZERO(rp);
FD_ZERO(wp);
events = width = 0;
for (mp = (pp = fds) + num; pp < mp; pp++)
if (pp->fd >= 0)
{
if (pp->fd > width)
width = pp->fd;
if (pp->events & CS_POLL_READ)
{
events |= CS_POLL_READ;
FD_SET(pp->fd, rp);
}
if (pp->events & CS_POLL_WRITE)
{
events |= CS_POLL_WRITE;
FD_SET(pp->fd, wp);
}
if (pp->events & CS_POLL_CONTROL)
{
events |= CS_POLL_CONTROL;
#if CS_LIB_SOCKET
FD_SET(pp->fd, ep);
#endif
}
}
if (!(events & CS_POLL_WRITE))
wp = 0;
#if CS_LIB_SOCKET
if (!(events & CS_POLL_READ))
rp = 0;
if (!(events & CS_POLL_CONTROL))
ep = 0;
messagef((state->id, NiL, -6, "poll: %s num=%d ms=%d sec=%d usec=%d", fmttime("%K", CSTIME()), num, ms, tp ? tp->tv_sec : 0, tp ? tp->tv_usec : 0));
num = select(width + 1, rp, wp, ep, tp);
#else
if (!(events & (CS_POLL_READ|CS_POLL_CONTROL)))
rp = 0;
messagef((state->id, NiL, -6, "poll: %s num=%d ms=%d", fmttime("%K", CSTIME()), num, ms);
num = select(width + 1, rp, wp, ms);
#endif
messagef((state->id, NiL, -6, "poll: %s num=%d", fmttime("%K", CSTIME()), num));
if (num < 0)
messagef((state->id, NiL, -1, "poll: select error"));
else
for (num = 0, pp = fds; pp < mp; pp++)
{
pp->status = 0;
if (pp->fd >= 0)
{
if (rp && FD_ISSET(pp->fd, rp))
{
#if CS_LIB_V10
long n;
if ((pp->event & CS_POLL_CONTROL) && ioctl(fd, FIONREAD, &n))
pp->status |= CS_POLL_CLOSE;
else if (!n)
pp->status |= CS_POLL_CONTROL;
else
#endif
pp->status |= CS_POLL_READ;
}
if (wp && FD_ISSET(pp->fd, wp))
pp->status |= CS_POLL_WRITE;
#if CS_LIB_SOCKET
if (ep && FD_ISSET(pp->fd, ep))
pp->status |= CS_POLL_CONTROL;
#endif
if (pp->status)
{
pp->status |= pp->events & (CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_USER);
num++;
}
}
}
return num;
#else
#if CS_LIB_STREAM
int n;
#if _lib_poll_fd_2
n = poll(num, fds, ms);
#else
n = poll(fds, num, ms);
#endif
if (n < 0)
messagef((state->id, NiL, -1, "poll: poll error"));
else if (n > 0)
{
int i;
#ifdef RS_HIPRI
struct strbuf buf;
buf.maxlen = 0;
#endif
for (mp = (pp = fds) + num, i = n; pp < mp; pp++)
{
if (pp->status)
{
pp->status |= pp->events & (CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_USER);
#ifdef RS_HIPRI
if (pp->status & CS_POLL_CONTROL)
{
int f = RS_HIPRI;
if (getmsg(pp->fd, NiL, &buf, &f))
pp->status &= ~CS_POLL_CONTROL;
}
#endif
if (--i <= 0)
break;
}
}
}
return n;
#else
errno = EINVAL;
messagef((state->id, NiL, -1, "poll: not supported"));
return -1;
#endif
#endif
}
int
_cs_poll(Cspoll_t* fds, int num, int ms)
{
return cspoll(&cs, fds, num, ms);
}

View file

@ -1,186 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return the port number given its name
*/
#include "cslib.h"
#include <hashkey.h>
/*
* map <type,serv> to port number
* e points to chars after service name
*/
unsigned long
csport(register Cs_t* state, const char* type, const char* serv)
{
unsigned long n;
char* t;
if (streq(serv, "reserved"))
return CS_PORT_RESERVED;
if (streq(serv, "normal"))
return CS_PORT_NORMAL;
n = strtol(serv, &t, 0);
if (t > serv && *t == '.')
strtol(t + 1, &t, 0);
if (*t)
{
if (strneq(serv, CS_SVC_INET, sizeof(CS_SVC_INET) - 1))
{
serv += sizeof(CS_SVC_INET) - 1;
#if CS_LIB_SOCKET || CS_LIB_V10
{
struct servent* sp;
#if CS_LIB_V10
if (sp = in_service(serv, type, 0))
return sp->port;
#endif
#if CS_LIB_SOCKET
if (sp = getservbyname(serv, type))
return ntohs(sp->s_port);
#endif
}
#endif
switch (strkey(serv))
{
case HASHKEY6('t','c','p','m','u','x'):
return 1;
case HASHKEY4('e','c','h','o'):
return 7;
case HASHKEY6('d','i','s','c','a','r'):
return 9;
case HASHKEY6('s','y','s','t','a','t'):
return 11;
case HASHKEY6('d','a','y','t','i','m'):
return 13;
case HASHKEY6('n','e','t','s','t','a'):
return 15;
case HASHKEY4('q','o','t','d'):
return 17;
case HASHKEY6('c','h','a','r','g','e'):
return 19;
case HASHKEY3('f','t','p'):
return 21;
case HASHKEY6('t','e','l','n','e','t'):
return 23;
case HASHKEY4('s','m','t','p'):
return 25;
case HASHKEY4('t','i','m','e'):
return 37;
case HASHKEY3('r','l','p'):
return 39;
case HASHKEY4('n','a','m','e'):
return 42;
case HASHKEY5('w','h','o','i','s'):
return 43;
case HASHKEY6('d','o','m','a','i','n'):
return 53;
case HASHKEY3('m','t','p'):
return 57;
case HASHKEY5('b','o','o','t','p'):
return 67;
case HASHKEY6('b','o','o','t','p','c'):
return 68;
case HASHKEY4('t','f','t','p'):
return 69;
case HASHKEY6('g','o','p','h','e','r'):
return 70;
case HASHKEY3('r','j','e'):
return 77;
case HASHKEY6('f','i','n','g','e','r'):
return 79;
case HASHKEY4('h','t','t','p'):
return 80;
case HASHKEY4('l','i','n','k'):
return 87;
case HASHKEY6('s','u','p','d','u','p'):
return 95;
case HASHKEY6('h','o','s','t','n','a'):
return 101;
case HASHKEY4('x',HASHKEYN('4'),HASHKEYN('0'),HASHKEYN('0')):
return 103;
case HASHKEY6('s','u','n','r','p','c'):
return 111;
case HASHKEY4('a','u','t','h'):
return 113;
case HASHKEY4('s','f','t','p'):
return 115;
case HASHKEY4('n','n','t','p'):
return 119;
case HASHKEY4('e','r','p','c'):
return 121;
case HASHKEY3('n','t','p'):
return 123;
case HASHKEY4('i','m','a','p'):
return 143;
case HASHKEY4('s','n','m','p'):
return 161;
case HASHKEY5('p','r','o','x','y'):
return 402;
case HASHKEY3('a','t','x'):
if (access("/etc/in.atxd", F_OK))
break;
return 512;
case HASHKEY4('b','i','f','f'):
return 512;
case HASHKEY4('e','x','e','c'):
return 512;
case HASHKEY5('l','o','g','i','n'):
return 513;
case HASHKEY3('w','h','o'):
return 513;
case HASHKEY5('s','h','e','l','l'):
return 514;
case HASHKEY6('s','y','s','l','o','g'):
return 514;
case HASHKEY6('p','r','i','n','t','e'):
return 515;
case HASHKEY4('t','a','l','k'):
return 517;
case HASHKEY5('n','t','a','l','k'):
return 518;
case HASHKEY5('r','o','u','t','e'):
return 520;
case HASHKEY5('t','i','m','e','d'):
return 525;
case HASHKEY5('t','e','m','p','o'):
return 526;
case HASHKEY4('u','u','c','p'):
return 540;
}
}
return CS_PORT_INVALID;
}
return n;
}
unsigned long
_cs_port(const char* type, const char* serv)
{
return csport(&cs, type, serv);
}

View file

@ -1,104 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* read at most size chars according to op
*
* CS_EXACT read exactly size chars
* multiple reads possible
* CS_LIMIT one read up to size chars
* CS_LINE '\n' '\r\n' '\n\r' terminated line up to size
* multiple reads possible
* CS_RESTART restart on interrupt
*
* 0 returned on eof
*/
#include "cslib.h"
ssize_t
csread(Cs_t* state, int fd, void* buf, size_t size, int op)
{
register ssize_t n;
register char* p;
register char* e;
int restart;
if (restart = !!(op & CS_RESTART))
op &= ~CS_RESTART;
p = (char*)buf;
e = p + size;
messagef((state->id, NiL, -9, "read(%d,%d,%s) before", fd, size, op == CS_EXACT ? "EXACT" : op == CS_LIMIT ? "LIMIT" : "LINE"));
if (op == CS_LINE && size > 1)
{
if ((n = cspeek(state, fd, buf, size - 1)) > 0 && (p[n] = 0, e = strchr(p, '\n')))
{
e++;
op = CS_EXACT;
}
else
{
while (p < e && (n = read(fd, p, 1)) == 1 && *p++ != '\n');
if (n <= 0 || p == (char*)buf || *(p - 1) != '\n')
goto bad;
n = p - (char*)buf;
messagef((state->id, NiL, -9, "read(%d,%d,%s) [%d] `%-.*s'", fd, size, op == CS_EXACT ? "EXACT" : op == CS_LIMIT ? "LIMIT" : "LINE", n, n, buf));
return n;
}
}
while (n = read(fd, p, e - p))
{
if (n < 0)
{
if (restart && errno == EINTR)
continue;
break;
}
messagef((state->id, NiL, -9, "read(%d,%d,%s) [%d] `%-.*s'", fd, size, op == CS_EXACT ? "EXACT" : op == CS_LIMIT ? "LIMIT" : "LINE", n, n, p));
p += n;
if (op == CS_LIMIT || op == CS_LINE && (*(p - 1) == '\n' || n > 1 && *(p - 1) == '\r' && *(p - 2) == '\n'))
return p - (char*)buf;
if (p >= e)
{
if (op == CS_EXACT)
return p - (char*)buf;
break;
}
messagef((state->id, NiL, -2, "read(%d,%d,%s) again [%d] `%-.*s'", fd, size, op == CS_EXACT ? "EXACT" : op == CS_LIMIT ? "LIMIT" : "LINE", p - (char*)buf, p - (char*)buf, (char*)buf));
}
bad:
if (p != (char*)buf || n < 0)
{
errno = EINVAL;
messagef((state->id, NiL, -2, "read(%d,%d,%s) invalid record [%d] `%-.*s'", fd, size, op == CS_EXACT ? "EXACT" : op == CS_LIMIT ? "LIMIT" : "LINE", p - (char*)buf, p - (char*)buf, (char*)buf));
return -1;
}
messagef((state->id, NiL, -2, "read(%d,%d,%s) eof", fd, size, op == CS_EXACT ? "EXACT" : op == CS_LIMIT ? "LIMIT" : "LINE"));
return 0;
}
ssize_t
_cs_read(int fd, void* buf, size_t size, int op)
{
return csread(&cs, fd, buf, size, op);
}

View file

@ -1,385 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* receive up to n fds from stream fd
* number of fds received is returned
*
* NOTE: cssend() only supported for local host
* for local host Csid_t.hid==0, Csid_t.pid not trusted
* for remote host csauth() can authenticate Csid_t.[ug]id
*/
#include "cslib.h"
#if CS_LIB_SOCKET_RIGHTS && !CS_LIB_STREAM
static int
sockrecv(int fd, Csid_t* id, int* fds, int n)
{
struct iovec iov;
struct msghdr msg;
#if _mem_msg_control_msghdr
struct
{
struct cmsghdr hdr;
int fds[OPEN_MAX + 1];
} ctl;
#else
#define msg_control msg_accrights
#define msg_controllen msg_accrightslen
#endif
msg.msg_name = 0;
msg.msg_namelen = 0;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
iov.iov_base = (caddr_t)id;
iov.iov_len = sizeof(*id);
#if _mem_msg_control_msghdr
msg.msg_control = (caddr_t)&ctl;
msg.msg_controllen = (char*)&ctl.fds[n] - (char*)&ctl;
ctl.hdr.cmsg_len = msg.msg_controllen;
ctl.hdr.cmsg_level = SOL_SOCKET;
ctl.hdr.cmsg_type = SCM_RIGHTS;
#else
msg.msg_control = (caddr_t)fds;
msg.msg_controllen = n * sizeof(fds[0]);
#endif
if (recvmsg(fd, &msg, 0) < 0) return -1;
id->hid = id->hid;
id->pid = id->pid;
id->uid = id->uid;
id->gid = id->gid;
#if _mem_msg_control_msghdr
if (ctl.hdr.cmsg_level != SOL_SOCKET || ctl.hdr.cmsg_type != SCM_RIGHTS)
return -1;
n = (ctl.hdr.cmsg_len - sizeof(ctl.hdr)) / sizeof(fds[0]);
for (fd = 0; fd < n; fd++)
fds[fd] = ctl.fds[fd];
return n;
#else
return msg.msg_controllen / sizeof(fds[0]);
#endif
}
#endif
int
csrecv(register Cs_t* state, int fd, Csid_t* id, int* fds, int n)
{
int oerrno;
Csid_t ignore;
#if CS_LIB_SOCKET
Sock_size_t namlen;
struct sockaddr_in nam;
#if CS_LIB_SOCKET_UN && !CS_LIB_STREAM
#if CS_LIB_SOCKET_RIGHTS
int rfd[OPEN_MAX + 1];
#endif
struct stat st;
#endif
#endif
#if CS_LIB_STREAM || CS_LIB_V10
int m;
struct strrecvfd rcv;
struct csfdhdr hdr;
#if CS_LIB_V10
struct tcpuser tcp;
#endif
#endif
#if CS_LIB_STREAM || CS_LIB_V10 || CS_LIB_SOCKET_RIGHTS
register int i;
#endif
messagef((state->id, NiL, -8, "recv(%d,%d) call", fd, n));
if (n < 1)
{
errno = EINVAL;
return -1;
}
if (!id) id = &ignore;
memzero(id, sizeof(*id));
oerrno = errno;
csprotect(&cs);
#if CS_LIB_V10
if (!ioctl(fd, TCPGETADDR, &tcp))
{
if ((fds[0] = tcp_accept(fd, &tcp)) < 0)
{
messagef((state->id, NiL, -1, "recv: %d: tcp accept error", fd));
return -1;
}
id->hid = tcp.faddr;
return 1;
}
messagef((state->id, NiL, -1, "recv: %d: ioctl TCPGETADDR error", fd));
#else
#if CS_LIB_SOCKET
namlen = sizeof(nam);
if ((fds[0] = accept(fd, (struct sockaddr*)&nam, &namlen)) >= 0)
{
#if CS_LIB_SOCKET_UN && !CS_LIB_STREAM
#if defined(__linux__) && defined(AF_UNSPEC)
if (nam.sin_family == AF_UNSPEC)
nam.sin_family = AF_UNIX;
#endif
if (nam.sin_family == AF_UNIX)
{
#if CS_LIB_SOCKET_RIGHTS
if (write(fds[0], "", 1) != 1)
{
messagef((state->id, NiL, -1, "recv: %d: ping write error", fd));
close(fds[0]);
return -1;
}
if (sockrecv(fds[0], id, rfd, 1) != 1)
{
messagef((state->id, NiL, -1, "recv: %d: sockrecv error", fd));
goto eperm;
}
if (fstat(rfd[0], &st))
{
messagef((state->id, NiL, -1, "recv: %d: %d: authentication stat error", fd, rfd[0]));
drop:
close(rfd[0]);
eperm:
close(fds[0]);
errno = EPERM;
return -1;
}
if ((st.st_mode & CS_AUTH_MASK) != CS_AUTH_MODE)
{
messagef((state->id, NiL, -1, "recv: %d: %d: invalid authentication mode %04o", fd, rfd[0], st.st_mode & CS_AUTH_MASK));
goto drop;
}
close(rfd[0]);
#else
if (fstat(fds[0], &st))
{
st.st_uid = geteuid();
st.st_gid = getegid();
}
#endif
id->uid = st.st_uid;
id->gid = st.st_gid;
}
else
#endif
if (nam.sin_family == AF_INET)
id->hid = (unsigned long)nam.sin_addr.s_addr;
return 1;
}
messagef((state->id, NiL, -1, "recv: %d: accept error", fd));
#endif
#endif
#if CS_LIB_STREAM || CS_LIB_V10
if (ioctl(fd, I_RECVFD, &rcv) < 0)
{
messagef((state->id, NiL, -1, "recv: %d: ioctl I_RECVFD error", fd));
switch (errno)
{
case EIO:
#ifdef EBADMSG
case EBADMSG:
#endif
break;
default:
return -1;
}
#if CS_LIB_STREAM
if (!(m = read(fd, &hdr, sizeof(hdr))))
#endif
m = read(fd, &hdr, sizeof(hdr));
if (m != sizeof(hdr))
{
errno = EINVAL;
messagef((state->id, NiL, -1, "recv: %d: hdr read error", fd));
return -1;
}
if (hdr.count <= 0)
{
errno = EINVAL;
messagef((state->id, NiL, -1, "recv: %d: invalid hdr count %d", fd, hdr.count));
return -1;
}
for (i = 0; i < hdr.count; i++)
{
if (ioctl(fd, I_RECVFD, &rcv) < 0)
{
messagef((state->id, NiL, -1, "recv: %d: ioctl I_RECVFD #%d error", fd, i + 1));
while (--i >= 0) close(fds[i]);
return -1;
}
fds[i] = rcv.fd;
}
id->pid = hdr.pid;
}
#ifdef I_ACCEPT
else if (ioctl(rcv.fd, I_ACCEPT, NiL) < 0)
{
messagef((state->id, NiL, -1, "recv: %d: ioctl I_ACCEPT error", fd));
close(rcv.fd);
return -1;
}
#endif
else
{
i = 1;
fds[0] = rcv.fd;
}
id->uid = rcv.uid;
id->gid = rcv.gid;
errno = oerrno;
return i;
#else
#if CS_LIB_SOCKET_RIGHTS
if ((i = sockrecv(fd, id, rfd, n + 1)) <= 1)
{
messagef((state->id, NiL, -1, "recv: %d: sockrecv error", fd));
nope:
if (i >= 0)
{
errno = EPERM;
while (--i >= 0) close(rfd[i]);
}
return -1;
}
if (fstat(rfd[0], &st))
{
messagef((state->id, NiL, -1, "recv: %d: %d: authentication stat error", fd, rfd[0]));
goto nope;
}
if ((st.st_mode & CS_AUTH_MASK) != CS_AUTH_MODE)
{
messagef((state->id, NiL, -1, "recv: %d: %d: invalid authentication mode %04o", fd, rfd[0], st.st_mode & CS_AUTH_MASK));
goto nope;
}
close(rfd[0]);
for (n = --i; i > 0; i--) fds[i - 1] = rfd[i];
id->uid = st.st_uid;
id->gid = st.st_gid;
return n;
#else
if (!access(CS_PROC_FD_TST, F_OK))
{
register int i;
register int j;
char* s;
unsigned long pid;
struct stat st;
s = state->temp;
if ((i = recv(fd, s, sizeof(state->temp), 0)) <= 0)
{
messagef((state->id, NiL, -1, "recv: %d: read error", fd));
return -1;
}
if (i >= sizeof(state->temp))
i = sizeof(state->temp) - 1;
s[i] = 0;
messagef((state->id, NiL, -8, "recv: `%s'", s));
pid = strtol(s, &s, 0);
i = strtol(s, &s, 0);
if (i < n)
n = i;
for (i = 0; i < n; i++)
fds[i] = strtol(s, &s, 0);
s = state->temp;
for (i = j = 0; i < n; i++)
{
sfsprintf(s, sizeof(state->temp), CS_PROC_FD_FMT, pid, fds[i]);
if (!stat(s, &st) && (fds[i] = open(s, (st.st_mode & (S_IRUSR|S_IWUSR)) == (S_IRUSR|S_IWUSR) ? O_RDWR : (st.st_mode & S_IWUSR) ? O_WRONLY : O_RDONLY)) >= 0)
j++;
}
if (id)
{
id->hid = 0;
id->pid = pid;
if (!stat(CS_PROC_FD_TST, &st))
{
id->uid = st.st_uid;
id->gid = st.st_gid;
}
else
{
id->uid = geteuid();
id->gid = getegid();
}
}
messagef((state->id, NiL, -8, "recv: %d fds", j));
return j;
}
errno = EINVAL;
return -1;
#endif
#endif
}
int
_cs_recv(int fd, Csid_t* id, int* fds, int n)
{
return csrecv(&cs, fd, id, fds, n);
}

View file

@ -1,953 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* connect stream server support
*/
#include "csslib.h"
#include <dirent.h>
#define OPEN_MIN 20
#if !defined(O_NONBLOCK) && defined(FNDELAY)
#define O_NONBLOCK FNDELAY
#endif
static Common_t state;
static int signals[] = /* caught by interrupt() */
{
SIGINT,
SIGQUIT,
SIGALRM,
SIGTERM,
#ifdef SIGCHLD
SIGCHLD,
#endif
};
/*
* catch interrupts
*/
static void
interrupt(int sig)
{
#if defined(SIGCHLD) && !_WINIX
if (sig != SIGCHLD)
#endif
signal(sig, interrupt);
#ifdef SIGCHLD
if (cs.interrupt != SIGCHLD)
#endif
cs.interrupt = sig;
}
/*
* called on exit
*/
static void
done(void)
{
cssclose(NiL);
}
/*
* drop fd ip
*/
static void
drop(Css_t* css, register Cspoll_t* pp)
{
register Cssfd_t* ip;
register int fd;
register int user;
if (!css)
css = state.main;
fd = pp->fd;
ip = &state.fdinfo[fd];
if (ip->css == css)
{
user = (ip->events & CS_POLL_USER) != 0;
ip->events = 0;
if (css->auth)
state.auth[fd].seq = 0;
if (ip->actionf)
{
ip->status = CS_POLL_CLOSE;
if ((*ip->actionf)(css, ip, css->disc) > 0)
fd = -1;
}
if (state.fdpolling > 0)
{
state.fdpolling--;
*pp = state.fdpoll[state.fdpolling];
}
css->fdpolling--;
if (ip->events & CS_POLL_CONNECT)
css->fdlistening--;
if (user)
css->fduser--;
else if (fd >= 0)
close(fd);
}
}
/*
* open the service
*/
Css_t*
cssopen(const char* path, Cssdisc_t* disc)
{
register Css_t* css;
int type;
int n;
char* s;
char* t;
struct stat st;
if (!state.servers)
{
csprotect(&cs);
if ((n = (int)strtol(astconf("OPEN_MAX", NiL, NiL), NiL, 0)) < OPEN_MIN)
n = OPEN_MIN;
if (!(s = newof(0, char, n * (sizeof(Cssfd_t) + sizeof(Cspoll_t) + sizeof(Auth_t)), 0)))
return 0;
state.fdpoll = (Cspoll_t*)(s);
state.fdinfo = (Cssfd_t*)(state.fdpoll + n);
state.auth = (Auth_t*)(state.fdinfo + n);
state.fdmax = n;
state.fdnext = -1;
state.pid = getpid();
if (!(css = newof(0, Css_t, 1, sizeof(Cssdisc_t))))
return 0;
css->id = cs.id;
css->disc = (Cssdisc_t*)(css + 1);
css->disc->version = CSS_VERSION;
state.servers = state.main = css;
atexit(done);
}
if (!path || (n = strlen(path) + 2) < 2 * CS_NAME_MAX)
n = 2 * CS_NAME_MAX;
if (!(css = newof(0, Css_t, 1, n)))
return 0;
n = n / 2 + 1;
css->next = state.servers;
state.servers = css;
if (!(css->state = csalloc(NiL)))
goto bad;
css->service = (char*)(css + 1);
css->path = css->service + n;
css->id = state.main->id;
css->disc = disc;
css->fdmax = state.fdmax;
if (path && strchr(path, '/'))
{
strcpy(css->path, path);
if (tokscan(css->path, NiL, "/dev/%s/%s/%s", &s, NiL, &t) != 3)
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, 3, "%s: invalid connect stream path", path);
goto bad;
}
type = *s;
if (s = strchr(t, '/'))
*s = 0;
strncpy(css->service, t, n);
errno = EBADF;
if ((css->fd = csopen(css->state, path, CS_OPEN_CREATE)) < 0)
{
if (css->disc->errorf)
{
if (errno == EEXIST)
(*css->disc->errorf)(css, css->disc, 3, "%s: server already running", path);
else
(*css->disc->errorf)(css, css->disc, ERROR_SYSTEM|3, "%s: cannot create connect stream", path);
}
goto bad;
}
css->disc->flags &= ~CSS_AUTHENTICATE;
}
else
{
sfsprintf(css->service, n, "/dev/fdp/local/%s", path);
path = (char*)cspath(css->state, 0, 0);
type = strmatch(path, "/dev/??p/*/*") ? path[5] : 'f';
css->perm = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
if ((css->disc->flags & CSS_AUTHENTICATE) && csopen(css->state, css->service, CS_OPEN_CREATE|CS_OPEN_MOUNT))
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, ERROR_SYSTEM|3, "%s: cannot create authentication directory", css->service);
goto bad;
}
}
strcpy(css->path, path);
if ((css->disc->flags & CSS_DAEMON) && csdaemon(css->state, (css->disc->flags & CSS_PRESERVE) ? ~0L : ((1<<css->fd)|(1<<2))))
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, 3, "cannot dive into background");
goto bad;
}
if (css->state->control)
{
strcpy(css->mount, css->state->mount);
css->control = strrchr(css->mount, '/') + 1;
strcpy(css->control + 1, CS_MNT_TAIL);
s = css->control - 1;
*s = 0;
if (stat(css->mount, &st))
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, 3, "%s: cannot stat service directory", css->mount);
goto bad;
}
if ((css->disc->flags & CSS_DAEMON) && chdir(css->mount))
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, 3, "%s: cannot set service directory", css->mount);
goto bad;
}
*s = '/';
/*
* get the fid for the global and local authentication dirs
* authentication files can only be in these dirs and
* must not be symlinks -- symlinks can point to untrusted
* places and other dirs may get untrusted filesystems
* mounted via the automounter
*/
n = 0;
while (s > css->mount)
if (*--s == '/' && ++n >= 3)
break;
if (n != 3)
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, 3, "%s: invalid mount directory", css->mount);
goto bad;
}
*s = 0;
if (lstat(css->mount, &st))
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, 3, "%s: invalid global authentication directory", css->mount);
goto bad;
}
*s = '/';
css->fid[0].dev = st.st_dev;
css->fid[0].ino = st.st_ino;
s = csvar(css->state, CS_VAR_LOCAL, 0);
if (lstat(s, &st) && (mkdir(s, S_IRWXU|S_IRWXG|S_IRWXO) || chmod(s, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) || lstat(s, &st)))
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, 3, "%s: invalid local authentication directory", s);
goto bad;
}
css->fid[1].dev = st.st_dev;
css->fid[1].ino = st.st_ino;
css->uid = st.st_uid;
css->gid = st.st_gid;
if (type == 't' && *(css->control - 2) != CS_MNT_OTHER && *(css->control - 2) != '.' && *(css->control - 2) != '*')
{
css->auth = 1;
state.nauth++;
CSTIME();
state.expire = cs.time + KEYEXPIRE;
css->conkey = state.pid + getppid() + css->uid + st.st_ino;
TOSS(css->conkey);
*css->control = CS_MNT_AUTH;
remove(css->mount);
css->newkey = css->conkey & KEYMASK;
if (close(open(css->mount, O_WRONLY|O_CREAT|O_TRUNC, st.st_mode & (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) ||
chmod(css->mount, st.st_mode & (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) ||
cschallenge(css->state, css->mount, NiL, &css->newkey))
{
if (css->disc->errorf)
(*css->disc->errorf)(css, css->disc, 3, "%s: cannot create service authentication file", css->mount);
goto bad;
}
chown(css->mount, -1, css->gid);
css->oldkey = css->newkey;
for (n = 0; n < (css->newkey & 0xff); n++)
CSTOSS(css->conkey, n);
css->challenge = (st.st_mode & S_IXOTH) ? 2 : 0;
}
*css->control = CS_MNT_PROCESS;
remove(css->mount);
s = css->buf;
if (type != 'f') s += sfsprintf(s, sizeof(css->buf) - (s - css->buf), "/n/%s", csname(css->state, 0));
sfsprintf(s, sizeof(css->buf) - (s - css->buf), "/proc/%d", getpid());
pathsetlink(css->buf, css->mount);
if (css->disc->flags & CSS_LOG)
{
*css->control = CS_MNT_OLDLOG;
strcpy(css->buf, css->mount);
*css->control = CS_MNT_LOG;
rename(css->mount, css->buf);
close(2);
open(css->mount, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
}
*css->control = CS_MNT_AUTH;
css->perm = st.st_mode & (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
if (css->disc->flags & CSS_DAEMON)
umask(~css->perm & (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
}
if ((css->disc->flags & CSS_INTERRUPT) && !(state.flags & CSS_INTERRUPT))
{
state.flags |= CSS_INTERRUPT;
for (n = 0; n < elementsof(signals); n++)
if (signal(signals[n], SIG_IGN) != SIG_IGN)
signal(signals[n], interrupt);
}
cssfd(css, css->fd, type == 'u' ? CS_POLL_READ : (CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_READ));
CSTIME();
return css;
bad:
cssclose(css);
return 0;
}
/*
* close the service
*/
int
cssclose(register Css_t* css)
{
register Css_t* pss;
register Css_t* xss;
register Css_t* oss;
register int i;
register int k;
static char mnt[] =
{
CS_MNT_AUTH,
CS_MNT_LOCK,
CS_MNT_PROCESS,
CS_MNT_STREAM
};
pss = 0;
xss = state.servers;
while (xss)
{
if (xss == css || !css)
{
if (xss->disc->exceptf && (xss->disc->flags & CSS_CLOSE))
(*xss->disc->exceptf)(css, CSS_CLOSE, 0, xss->disc);
if (state.fdinfo)
{
for (i = k = 0; i < state.fdpolling;)
{
if (state.fdinfo[state.fdpoll[i].fd].css == xss)
drop(xss, &state.fdpoll[i]);
else
state.fdpoll[k++] = state.fdpoll[i++];
}
state.fdpolling = k;
}
if (state.pid == getpid() && xss->control)
for (i = 0; i < elementsof(mnt); i++)
{
*xss->control = mnt[i];
remove(xss->control);
}
if (xss->auth)
state.nauth--;
oss = xss;
xss = xss->next;
if (pss)
pss->next = oss->next;
else
state.servers = oss->next;
if (oss->state)
csfree(oss->state);
free(oss);
if (css)
return 0;
}
else
{
pss = xss;
xss = xss->next;
}
}
if (css)
return -1;
if (!state.servers && state.fdpoll)
{
free(state.fdpoll);
state.fdpoll = 0;
}
return 0;
}
/*
* file descriptor manipulation
*
* CS_POLL_DUP(n) move fd to n
* CS_POLL_MOVE(n) move fd to n
* CS_POLL_PRI(n) set fd priority (not yet)
* CS_POLL_CLOSE close+delete fd from table
* CS_POLL_AUTH|* authenticate then poll
* CS_POLL_* poll
* CS_POLL_USER| don't close unless CS_POLL_CLOSE
*/
Cssfd_t*
cssfd(register Css_t* css, register int fd, unsigned long op)
{
register Cssfd_t* ip;
register Cspoll_t* pp;
register int n;
register int nfd;
register int cmd;
int flags;
#if DEBUG
int ofd = fd;
unsigned long oop = op;
#endif
if (!css)
css = state.main;
again:
if (fd < 0 || fd >= state.fdmax)
return 0;
ip = state.fdinfo + fd;
if (op == 0)
return ip->events ? ip : (Cssfd_t*)0;
if (op & CS_POLL_ARG)
{
cmd = op & CS_POLL_MASK;
nfd = (op >> CS_POLL_SHIFT) & CS_POLL_MASK;
op = nfd == CS_POLL_MASK ? CS_POLL_CLOSE : 0;
}
else
cmd = 0;
if (op != CS_POLL_CLOSE)
{
if (op & CS_POLL_AUTH)
{
if (!css->auth)
op &= ~CS_POLL_AUTH;
}
if (op & CS_POLL_CONNECT)
{
op &= ~(CS_POLL_CONTROL|CS_POLL_WRITE);
op |= CS_POLL_READ;
}
for (n = 0;; n++)
{
if (n >= state.fdpolling)
{
if (!(op & CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_READ|CS_POLL_WRITE))
return 0;
if (fcntl(fd, F_SETFD, FD_CLOEXEC) && errno == EBADF)
return 0;
if ((op & (CS_POLL_AUTH|CS_POLL_CONNECT)) == CS_POLL_AUTH)
{
state.auth[fd].seq = 1;
state.auth[fd].expire = cs.time + EXPIRE;
}
pp = state.fdpoll + state.fdpolling++;
pp->fd = fd;
pp->events = op;
pp->status = 0;
ip->css = css;
ip->fd = fd;
ip->actionf = css->disc->actionf;
ip->data = 0;
ip->events = op;
ip->set = 0;
css->fdpolling++;
if (ip->events & CS_POLL_BEFORE)
state.fdbefore++;
if (ip->events & CS_POLL_CONNECT)
css->fdlistening++;
if (ip->events & CS_POLL_USER)
css->fduser++;
#if DEBUG
goto show;
#else
return ip;
#endif
}
if (state.fdpoll[n].fd == fd)
{
switch (cmd)
{
case 0:
if (ip->css != css)
return 0;
if (css->fd != fd)
{
if (ip->events & CS_POLL_BEFORE)
state.fdbefore--;
if (ip->events & CS_POLL_CONNECT)
css->fdlistening--;
if (ip->events & CS_POLL_USER)
css->fduser--;
state.fdpoll[n].events = ip->events = op;
if (ip->events & CS_POLL_BEFORE)
state.fdbefore++;
if (ip->events & CS_POLL_CONNECT)
css->fdlistening++;
if (ip->events & CS_POLL_USER)
css->fduser++;
if (op & CS_POLL_WRITE)
{
#ifdef O_NONBLOCK
if (!(ip->set & CS_POLL_WRITE))
{
ip->set |= CS_POLL_WRITE;
if ((flags = fcntl(fd, F_GETFL, 0)) >= 0)
{
flags |= O_NONBLOCK;
fcntl(fd, F_SETFL, flags);
messagef((state.main->id, NiL, -4, "cssfd: %d O_NONBLOCK", fd));
}
}
#endif
messagef((state.main->id, NiL, -4, "cssfd: %d CS_POLL_WRITE", fd));
}
}
break;
case CS_POLL_DUP:
/*ip->actionf = 0;*/
css = ip->css;
fd = nfd;
op = state.fdpoll[n].events;
goto again;
case CS_POLL_MOVE:
if (fcntl(nfd, F_SETFD, FD_CLOEXEC) && errno == EBADF)
return 0;
state.fdpoll[n].fd = nfd;
if (fd == css->fd)
css->fd = nfd;
state.fdinfo[nfd] = *ip;
ip = state.fdinfo + nfd;
ip->fd = nfd;
break;
case CS_POLL_PRI:
break;
}
#if DEBUG
show:
if (error_info.trace <= -9)
{
errorf(state.main->id, NiL, -9, "cssfd: pending=%d polling=%d next=%d fd=%d op=0x%08lx", state.fdpending, state.fdpolling, state.fdnext, ofd, oop);
for (n = 0; n < state.fdpolling; n++)
errorf(state.main->id, NiL, -9, "cssfd: index=%d fd=%d events=%06o actionf=%p", n, state.fdpoll[n].fd, state.fdpoll[n].events, state.fdinfo[state.fdpoll[n].fd].actionf);
}
#endif
return ip;
}
}
}
else if (css->fd != fd)
{
for (n = 0; n < state.fdpolling; n++)
if (state.fdpoll[n].fd == fd)
{
drop(state.fdinfo[fd].css, &state.fdpoll[n]);
break;
}
if (n >= state.fdpolling)
close(fd);
#if DEBUG
ip = 0;
goto show;
#endif
}
return 0;
}
/*
* poll for the next fd event
* some events may be pending from the last call
*/
Cssfd_t*
csspoll(unsigned long ms, unsigned long flags)
{
register Css_t* css;
register Cspoll_t* pp;
register Cssfd_t* ip;
register Auth_t* ap;
register int fd;
char* s;
char* t;
int n;
int fdnew;
int status;
int to;
int oerrno;
int err;
int clrerr;
int sig;
int clrsig;
unsigned long key;
unsigned long z;
unsigned long timeout;
Csid_t id;
struct stat st;
char** vp;
char* va[8];
if (state.polling && !(flags & CSS_RECURSIVE))
{
errno = EBUSY;
return 0;
}
state.polling++;
if (ms == CS_NEVER)
timeout = 0;
else
timeout = CSTIME() + ((ms + 999) / 1000);
oerrno = errno;
for (;;)
{
while (state.fdpending <= 0)
{
CSTIME();
if (timeout && timeout >= cs.time)
{
errno = oerrno;
return 0;
}
if (state.nauth && cs.time > state.expire)
{
state.expire = cs.time + KEYEXPIRE;
for (css = state.servers; css; css = css->next)
if (css->auth)
{
css->oldkey = css->newkey;
n = cs.time & 077;
do TOSS(css->newkey); while (n--);
css->newkey &= KEYMASK;
*css->control = CS_MNT_AUTH;
if (cschallenge(css->state, css->mount, NiL, &css->newkey))
css->newkey = css->oldkey;
}
for (pp = state.fdpoll; pp < state.fdpoll + state.fdpolling;)
{
ap = state.auth + pp->fd;
if (ap->seq && cs.time > ap->expire)
drop(state.fdinfo[pp->fd].css, pp);
else
pp++;
}
}
to = ms;
for (css = state.servers; css; css = css->next)
{
css->fdpending = 0;
if (css->disc->timeout)
{
if (css->timeout_last != css->disc->timeout)
css->timeout_last = css->timeout_remain = css->disc->timeout;
if (to > css->timeout_remain)
to = css->timeout_remain;
}
if (css->disc->wakeup)
{
if (css->wakeup_last != css->disc->wakeup)
css->wakeup_last = css->wakeup_remain = css->disc->wakeup;
if (to > css->wakeup_remain)
to = css->wakeup_remain;
}
}
if (state.fdbefore)
for (pp = state.fdpoll; pp < state.fdpoll + state.fdpolling;)
{
if (pp->events & CS_POLL_BEFORE)
{
ip = state.fdinfo + pp->fd;
ip->status = CS_POLL_BEFORE;
if (ip->actionf && (*ip->actionf)(ip->css, ip, ip->css->disc) < 0)
{
drop(ip->css, pp);
continue;
}
}
pp++;
}
z = cs.time;
if ((state.fdpending = cspoll(&cs, state.fdpoll, state.fdpolling, to)) < 0)
{
err = errno;
sig = (err == EINTR) ? cs.interrupt : 0;
clrsig = 0;
clrerr = 0;
}
else
{
err = 0;
sig = 0;
}
state.fdloop = 1;
CSTIME();
if (state.fdpending)
z = (cs.time - z) * 1000;
else
z = to;
if (ms != CS_NEVER)
{
if (ms > z)
ms -= z;
else
timeout = cs.time;
}
if (state.fdpending > 0)
for (pp = state.fdpoll; pp < state.fdpoll + state.fdpolling; pp++)
if (pp->status & (CS_POLL_READ|CS_POLL_WRITE))
state.fdinfo[pp->fd].css->fdpending++;
for (css = state.servers; css; css = css->next)
if (css->disc->exceptf)
{
if (css->disc->timeout)
{
if (css->fdpending)
css->timeout_remain = css->disc->timeout;
else if (css->timeout_remain <= z)
{
if ((css->disc->flags & CSS_DORMANT) && css->fdpolling <= (css->fdlistening + css->fduser))
(*css->disc->exceptf)(css, CSS_DORMANT, 0, css->disc);
else if (css->disc->flags & CSS_TIMEOUT)
(*css->disc->exceptf)(css, CSS_TIMEOUT, 0, css->disc);
css->timeout_last = css->timeout_remain = css->disc->timeout;
}
else
css->timeout_remain -= z;
}
if (css->disc->wakeup)
{
messagef((state.main->id, NiL, -4, "csspoll: pending=%d polling=%d z=%I*d wakeup=%I*d remain=%I*d", state.fdpending, state.fdpolling, sizeof(z), z, sizeof(css->disc->wakeup), css->disc->wakeup, sizeof(css->wakeup_remain), css->wakeup_remain));
if (css->wakeup_remain <= z)
{
(*css->disc->exceptf)(css, CSS_WAKEUP, 0, css->disc);
css->wakeup_last = css->wakeup_remain = css->disc->wakeup;
}
else
css->wakeup_remain -= z;
}
if (err)
{
if ((css->disc->flags & CSS_INTERRUPT) && (sig || err == EINTR))
{
if (!sig)
clrerr = 1;
else if ((*css->disc->exceptf)(css, CSS_INTERRUPT, sig, css->disc) >= 0)
clrsig = 1;
}
else if (css->disc->flags & CSS_ERROR)
{
if ((*css->disc->exceptf)(css, CSS_ERROR, err, css->disc) >= 0)
clrerr = 1;
}
}
}
if (err && (ms != CS_NEVER || (flags & CSS_INTERRUPT) && (sig || err == EINTR) && !clrsig || (flags & CSS_ERROR) && !sig && err != EINTR && !clrerr))
{
errno = err;
state.polling--;
return 0;
}
}
do
{
if (++state.fdnext >= state.fdpolling)
{
if (state.fdloop-- < 0)
break;
state.fdnext = 0;
}
pp = state.fdpoll + state.fdnext;
fd = pp->fd;
messagef((state.main->id, NiL, -9, "csspoll: pending=%d polling=%d next=%d fd=%d status=%06o", state.fdpending, state.fdpolling, state.fdnext, fd, pp->status));
ip = state.fdinfo + fd;
css = ip->css;
status = pp->status & ~(CS_POLL_BEFORE|CS_POLL_USER);
pp->status = 0;
switch (status)
{
case CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_READ:
if (css->auth)
{
if (csrecv(css->state, fd, &id, &fdnew, 1) == 1)
{
state.auth[fdnew].id = id;
cssfd(css, fdnew, CS_POLL_AUTH|CS_POLL_READ);
}
break;
}
/*FALLTHROUGH*/
case CS_POLL_CONNECT|CS_POLL_READ:
if (csrecv(css->state, fd, &id, &fdnew, 1) == 1 &&
(ip = cssfd(css, fdnew, CS_POLL_READ)) &&
css->disc->acceptf &&
(fdnew = (*css->disc->acceptf)(css, ip, &id, NiL, css->disc)) != ip->fd)
cssfd(css, ip->fd, fdnew >= 0 ? CS_POLL_CMD(fdnew, CS_POLL_MOVE) : CS_POLL_CLOSE);
break;
case CS_POLL_AUTH|CS_POLL_READ:
switch ((ap = state.auth + fd)->seq)
{
case 1:
if ((n = csread(css->state, fd, css->buf, sizeof(css->buf), CS_LINE)) <= 0)
goto reject;
css->buf[n - 1] = 0;
if (tokscan(css->buf, &t, "%lu", &key) != 1)
goto reject;
switch (key)
{
case CS_KEY_SEND:
n = sfsprintf(css->tmp, sizeof(css->tmp), "%s\n", css->mount);
if (cswrite(css->state, fd, css->tmp, n) != n)
goto reject;
break;
default:
if (key <= CS_KEY_MAX || key != css->newkey && key != css->oldkey || tokscan(t, NiL, "%ld", &ap->id.pid) != 1)
goto reject;
if (!(ap->seq = css->challenge))
{
st.st_uid = css->uid;
st.st_gid = css->gid;
goto ok;
}
css->conkey ^= cs.time ^ ap->id.pid;
n = cs.time & 017;
do TOSS(css->conkey); while (n--);
ap->atime = css->conkey & KEYMASK;
n = cs.time & 07;
do TOSS(css->conkey); while (n--);
ap->mtime = css->conkey & KEYMASK;
n = sfsprintf(css->tmp, sizeof(css->tmp), "%lu %lu\n", (unsigned long)ap->atime, (unsigned long)ap->mtime);
if (cswrite(css->state, fd, css->tmp, n) != n)
goto reject;
ap->expire = cs.time + EXPIRE;
break;
}
break;
case 2:
ap->seq = 0;
if (cs.time > ap->expire || (n = csread(css->state, fd, css->buf, sizeof(css->buf), CS_LINE)) <= 1)
goto reject;
css->buf[n - 1] = 0;
if (t = strchr(css->buf, ' '))
*t++ = 0;
if (!(s = strrchr(css->buf, '/')))
goto reject;
*s = 0;
if (lstat(css->buf, &st))
goto reject;
*s = '/';
for (n = 0; n < elementsof(css->fid); n++)
#if _UWIN
if (css->fid[n].dev == st.st_dev)
#else
if (css->fid[n].dev == st.st_dev && css->fid[n].ino == st.st_ino)
#endif
break;
if (n >= elementsof(css->fid))
goto reject;
if (lstat(css->buf, &st))
{
/*
* kick the NonFS cache
*/
if (!(s = strrchr(css->buf, '.')))
goto reject;
*s = 0;
close(open(css->buf, O_WRONLY|O_CREAT|O_TRUNC, 0));
remove(css->buf);
*s = '.';
if (lstat(css->buf, &st))
goto reject;
}
if ((st.st_mode & CS_AUTH_MODE) != CS_AUTH_MODE ||
ap->atime != st.st_atime ||
ap->mtime != st.st_mtime)
goto reject;
ok:
if (cswrite(css->state, fd, "\n", 1) != 1)
goto reject;
pp->events &= ~CS_POLL_AUTH;
if (css->disc->acceptf)
{
ip = state.fdinfo + pp->fd;
ap->id.uid = st.st_uid;
ap->id.gid = st.st_gid;
vp = va;
while ((vp < &va[elementsof(va) - 1]) &&
(*vp++ = t) && (t = strchr(t, ' ')))
*t++ = 0;
*vp = 0;
if ((fdnew = (*css->disc->acceptf)(css, ip, &ap->id, *va ? va : (char**)0, css->disc)) != ip->fd)
cssfd(css, ip->fd, fdnew >= 0 ? CS_POLL_CMD(fdnew, CS_POLL_MOVE) : CS_POLL_CLOSE);
}
break;
default:
goto reject;
}
break;
case CS_POLL_READ|CS_POLL_WRITE:
case CS_POLL_WRITE:
pp->events &= ~CS_POLL_WRITE;
/*FALLTHROUGH*/
case CS_POLL_READ:
ip->status = status;
messagef((state.main->id, NiL, -9, "csspoll: status=%06o fd=%d actionf=%p", status, fd, ip->actionf));
if (!ip->actionf || (n = (*ip->actionf)(css, ip, css->disc)) == 0)
{
state.fdpending--;
state.polling--;
return ip;
}
if (n < 0)
goto reject;
break;
case CS_POLL_AUTH:
case CS_POLL_AUTH|CS_POLL_CONNECT:
case CS_POLL_CONNECT:
break;
case 0:
continue;
default:
reject:
drop(css, pp);
state.fdnext--;
break;
}
state.fdpending--;
} while (state.fdpending);
}
}

View file

@ -1,129 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* connect stream server interface definitions
*/
#ifndef _CSS_H
#define _CSS_H
#define CSS_VERSION 19970717L
#ifndef CS_INTERFACE
#define CS_INTERFACE 2
#endif
#define CSS_AUTHENTICATE (1<<10) /* authenticate connections */
#define CSS_DAEMON (1<<0) /* become daemon proc */
#define CSS_LOG (1<<1) /* stderr to daemon log file */
#define CSS_PRESERVE (1<<2) /* preserve daemon fd's */
#define CSS_RECURSIVE (1<<3) /* allow recursive csspoll() */
#define CSS_CLOSE (1<<4) /* server close exception */
#define CSS_DORMANT (1<<5) /* dormant timeout exception */
#define CSS_ERROR (1<<6) /* error exception */
#define CSS_INTERRUPT (1<<7) /* interrupt exception */
#define CSS_TIMEOUT (1<<8) /* timeout exception */
#define CSS_WAKEUP (1<<9) /* wakeup exception */
#define CS_POLL_DUP 1
#define CS_POLL_MOVE 2
#define CS_POLL_PRI 3
#define CS_POLL_ARG 0x80000000
#define CS_POLL_SHIFT 16
#define CS_POLL_MASK 0x00007fff
#define CS_POLL_CMD(f,c)(CS_POLL_ARG|(c)|(((long)(f)&CS_POLL_MASK)<<CS_POLL_SHIFT))
#include <cs.h>
struct Css_s;
struct Cssdisc_s;
struct Cssfd_s;
typedef struct Css_s Css_t;
typedef struct Cssdisc_s Cssdisc_t;
typedef struct Cssfd_s Cssfd_t;
struct Cssdisc_s /* user discipline */
{
unsigned long version; /* CSS_VERSION */
unsigned long flags; /* CSS_* flags */
unsigned long timeout; /* timeout in ms, 0 if none */
unsigned long wakeup; /* wakeup in ms, 0 if none */
Error_f errorf; /* error message handler */
int (*acceptf)(Css_t*, Cssfd_t*, Csid_t*, char**, Cssdisc_t*);
/* accept new connection/fd */
int (*actionf)(Css_t*, Cssfd_t*, Cssdisc_t*);
/* fd state change action */
int (*exceptf)(Css_t*, unsigned long, unsigned long, Cssdisc_t*);
/* poll exception action */
};
struct Cssfd_s /* fd info */
{
int fd; /* fd */
int status; /* action status */
int (*actionf)(Css_t*, Cssfd_t*, Cssdisc_t*);
/* css.actionf by default */
void* data; /* user data, 0 by default */
#ifdef _CSS_FD_PRIVATE_
_CSS_FD_PRIVATE_
#endif
};
struct Css_s /* connect stream server state */
{
char* id; /* library identifier */
char* service; /* service name */
char* path; /* service path */
int fd; /* service fd */
int fdmax; /* max # serviceable fd's */
int perm; /* service permissions */
char mount[PATH_MAX];/* service mount path */
char* control; /* CS_MNT_* in css.mount */
Cs_t* state; /* from csalloc() */
#ifdef _CSS_PRIVATE_
_CSS_PRIVATE_
#endif
};
#if _BLD_cs && defined(__EXPORT__)
#define extern __EXPORT__
#endif
extern Css_t* cssopen(const char*, Cssdisc_t*);
extern Cssfd_t* cssfd(Css_t*, int, unsigned long);
extern Cssfd_t* csspoll(unsigned long, unsigned long);
extern int cssclose(Css_t*);
#undef extern
#endif

View file

@ -1,223 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* send n fds to stream fd
*/
#include "cslib.h"
int
cssend(register Cs_t* state, int fd, int* fds, int n)
{
#if CS_LIB_STREAM || CS_LIB_V10
register int i;
struct csfdhdr hdr;
if (n > 0)
{
#if CS_LIB_STREAM
struct strbuf dat;
#endif
csprotect(&cs);
hdr.count = n;
hdr.pid = getpid();
#if CS_LIB_STREAM
dat.buf = "";
dat.len = 0;
if (putmsg(fd, NiL, &dat, 0) < 0 || write(fd, &hdr, sizeof(hdr)) != sizeof(hdr))
#else
if (write(fd, &hdr, sizeof(hdr)) != sizeof(hdr))
#endif
{
messagef((state->id, NiL, -1, "send: %d: hdr write error", fd));
return -1;
}
for (i = 0; i < n; i++)
if (ioctl(fd, I_SENDFD, FDARG(fds[i])))
{
messagef((state->id, NiL, -1, "send: %d: ioctl I_SENDFD error", fd));
return -1;
}
}
return 0;
#else
#if CS_LIB_SOCKET_RIGHTS
register char* s;
register int i;
struct iovec iov;
Csid_t id;
struct msghdr msg;
struct
{
#if _mem_msg_control_msghdr
struct cmsghdr hdr;
#else
#define msg_control msg_accrights
#define msg_controllen msg_accrightslen
#endif
int fds[OPEN_MAX + 1];
} ctl;
char tmp[PATH_MAX + 1];
csprotect(&cs);
if (n >= elementsof(ctl.fds))
{
errno = EINVAL;
return -1;
}
/*
* the first fd is to verify uid,gid in csrecv()
*/
s = csvar(state, CS_VAR_LOCAL, 0);
if (eaccess(s, X_OK) && (mkdir(s, S_IRWXU|S_IRWXG|S_IRWXO) || chmod(s, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)))
{
messagef((state->id, NiL, -1, "send: %d: %s: invalid authentication directory ", fd, s));
return -1;
}
if (!(s = pathtemp(tmp, sizeof(tmp), s, "cs", 0)))
{
messagef((state->id, NiL, -1, "send: %d: authentication tmp file error", fd));
return -1;
}
if ((i = open(s, O_WRONLY|O_CREAT|O_TRUNC, CS_AUTH_MODE)) < 0 || chmod(s, CS_AUTH_MODE) < 0)
{
messagef((state->id, NiL, -1, "send: %d: %s: authentication file creat error", fd, s));
return -1;
}
if (remove(s))
{
messagef((state->id, NiL, -1, "send: %d: %s: authentication file remove error", fd, s));
close(i);
errno = EPERM;
return -1;
}
ctl.fds[0] = i;
for (i = 0; i < n; i++)
ctl.fds[i + 1] = fds[i];
id.hid = 0;
id.pid = getpid();
id.uid = geteuid();
id.gid = getegid();
msg.msg_name = 0;
msg.msg_namelen = 0;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
iov.iov_base = (caddr_t)&id;
iov.iov_len = sizeof(id);
msg.msg_control = (caddr_t)&ctl;
msg.msg_controllen = (char*)&ctl.fds[n + 1] - (char*)&ctl;
#if _mem_msg_control_msghdr
ctl.hdr.cmsg_len = msg.msg_controllen;
ctl.hdr.cmsg_level = SOL_SOCKET;
ctl.hdr.cmsg_type = SCM_RIGHTS;
#endif
#ifdef EMSGSIZE
n = 0;
while ((i = sendmsg(fd, &msg, 0) < 0 ? -1 : 0) < 0 && errno == EMSGSIZE && n++ < 5)
sleep(1);
#else
i = sendmsg(fd, &msg, 0) < 0 ? -1 : 0;
#endif
if (i) messagef((state->id, NiL, -1, "send: %d: sendmsg error", fd));
close(ctl.fds[0]);
return i;
#else
messagef((state->id, NiL, -8, "send(%d,%d) call", fd, n));
if (!access(CS_PROC_FD_TST, F_OK))
{
register int i;
register int j;
register char* s;
static struct
{
int* fds;
int num;
int max;
} hold;
/*
* the sent fd's must be kept open until
* the other side receives them, so we dup
* and hold them open until the next cssend()
*/
if (hold.fds)
for (i = 0; i < hold.num; i++)
if (hold.fds[i] >= 0)
{
close(hold.fds[i]);
hold.fds[i] = 0;
}
if (n > hold.max)
{
hold.max = roundof(n, 8);
hold.fds = newof(hold.fds, int, hold.max, 0);
}
s = state->temp;
s += sfsprintf(s, sizeof(state->temp), "%lu %d", getpid(), n);
if (hold.fds)
{
hold.num = n;
for (i = 0; i < n; i++)
{
if ((j = hold.fds[i] = dup(fds[i])) < 0)
j = fds[i];
else fcntl(j, F_SETFD, FD_CLOEXEC);
s += sfsprintf(s, sizeof(state->temp) - (s - state->temp), " %d", j);
}
}
else for (i = 0; i < n; i++)
s += sfsprintf(s, sizeof(state->temp) - (s - state->temp), " %d", fds[i]);
s += sfsprintf(s, sizeof(state->temp) - (s - state->temp), "\n");
n = s - state->temp;
messagef((state->id, NiL, -8, "send(%d, %-*.*s) call", fd, n - 1, n - 1, state->temp));
i = send(fd, state->temp, n, 0) == n ? 0 : -1;
if (i) messagef((state->id, NiL, -1, "send: %d: write error", fd));
return i;
}
errno = EINVAL;
messagef((state->id, NiL, -1, "send: %d: not supported", fd));
return -1;
#endif
#endif
}
int
_cs_send(int fd, int* fds, int n)
{
return cssend(&cs, fd, fds, n);
}

View file

@ -1,219 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* obsolete generic server state machine
* <css.h> provides a discipline interface with multiple servers
*/
#include "csslib.h"
struct Server_s
{
Cssdisc_t disc;
Css_t* css;
void* handle;
int (*done)(void*, int);
int (*con)(void*, int, Csid_t*, int, char**);
int (*rd)(void*, int);
int (*wr)(void*, int);
int (*to)(void*);
};
static int
acceptf(Css_t* css, Cssfd_t* fp, Csid_t* ip, char** av, Cssdisc_t* disc)
{
register Server_t* server = (Server_t*)disc;
return (*server->con)(server->handle, fp->fd, ip, 0, av) ? -1 : fp->fd;
}
static int
actionf(Css_t* css, Cssfd_t* fp, Cssdisc_t* disc)
{
register Server_t* server = (Server_t*)disc;
switch (fp->status)
{
case CS_POLL_READ:
if (server->rd)
return (*server->rd)(server->handle, fp->fd) < 0 ? -1 : 1;
break;
case CS_POLL_WRITE:
if (server->wr)
return (*server->wr)(server->handle, fp->fd) < 0 ? -1 : 1;
break;
}
return 0;
}
static int
exceptf(Css_t* css, unsigned long op, unsigned long arg, Cssdisc_t* disc)
{
register Server_t* server = (Server_t*)disc;
switch (op)
{
case CSS_CLOSE:
if (server->done)
(*server->done)(server->handle, 0);
return 0;
case CSS_INTERRUPT:
if (server->done && !(*server->done)(server->handle, EXIT_TERM(arg)))
return 1;
error(ERROR_SYSTEM|3, "%s: interrupt exit", fmtsignal(arg));
return -1;
case CSS_DORMANT:
case CSS_TIMEOUT:
case CSS_WAKEUP:
return !server->to ? 0 : (*server->to)(server->handle) < 0 ? -1 : 1;
}
error(ERROR_SYSTEM|3, "poll error [op=%lu arg=%lu]", op, arg);
return -1;
}
int
csfd(Cs_t* state, int fd, int op)
{
return !state->server || cssfd(state->server->css, fd, op) ? -1 : 0;
}
/*
* csserve() wakeup and timeout are mutually exclusive
*/
unsigned long
cstimeout(register Cs_t* state, unsigned long ms)
{
unsigned long rv;
if (!state->server)
return CS_NEVER;
state->server->css->disc->wakeup = 0;
rv = state->server->css->disc->timeout;
state->server->css->disc->timeout = ms;
return rv;
}
/*
* csserve() wakeup and timeout are mutually exclusive
*/
unsigned long
cswakeup(Cs_t* state, unsigned long ms)
{
unsigned long rv;
if (!state->server)
return CS_NEVER;
state->server->css->disc->timeout = 0;
rv = state->server->css->disc->wakeup;
state->server->css->disc->wakeup = ms;
return rv;
}
/*
* server state machine
*/
void
csserve(Cs_t* state, void* handle, const char* path, void* (*init)(void*, int), int (*done)(void*, int), int (*con)(void*, int, Csid_t*, int, char**), int (*rd)(void*, int), int (*wr)(void*, int), int (*to)(void*))
{
register Server_t* server;
if (!con && !rd)
error(ERROR_PANIC, "a connect or read handler must be supplied");
if (!(server = newof(0, Server_t, 1, 0)))
error(ERROR_SYSTEM|3, "out of space");
state->server = server;
server->disc.version = CSS_VERSION;
server->disc.flags = CSS_DAEMON|CSS_LOG|CSS_CLOSE|CSS_ERROR|CSS_INTERRUPT|CSS_TIMEOUT|CSS_WAKEUP;
server->handle = handle;
server->con = con;
if (server->con)
server->disc.acceptf = acceptf;
server->rd = rd;
server->wr = wr;
if (server->rd || server->wr)
server->disc.actionf = actionf;
server->to = to;
server->disc.errorf = errorf;
server->disc.exceptf = exceptf;
server->done = done;
close(0);
if (!(server->css = cssopen(path, (Cssdisc_t*)server)))
exit(1);
error_info.id = server->css->service;
state->id = server->css->id;
state->cs = server->css->path;
state->control = state->mount + (server->css->control - server->css->mount);
strcpy(state->mount, server->css->mount);
#ifdef SIGCHLD
if (!done)
signal(SIGCHLD, SIG_DFL);
#endif
/*
* we the
* are
* ser
* ver
*
* in background
* no controlling tty
* pwd is the service data directory
* stdin is the connect stream
* stdout is /dev/null
* stderr is CS_MNT_LOG in the service data directory
* umask matches service mode
*/
if (init)
server->handle = (*init)(server->handle, server->css->fdmax);
csspoll(CS_NEVER, 0);
}
int
_cs_fd(int fd, int op)
{
return csfd(&cs, fd, op);
}
void
_cs_serve(void* handle, const char* path, void* (*init)(void*, int), int (*done)(void*, int), int (*con)(void*, int, Csid_t*, int, char**), int (*rd)(void*, int), int (*wr)(void*, int), int (*to)(void*))
{
csserve(&cs, handle, path, init, done, con, rd, wr, to);
}
unsigned long
_cs_timeout(unsigned long ms)
{
return cstimeout(&cs, ms);
}
unsigned long
_cs_wakeup(unsigned long ms)
{
return cswakeup(&cs, ms);
}

View file

@ -1,110 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* connect stream server support
*/
#ifndef _CSSLIB_H
#define _CSSLIB_H
#include "cslib.h"
#include <error.h>
#include <sig.h>
#include <tok.h>
#define EXPIRE 60
#define KEYEXPIRE (60*5)
#define KEYMASK 0x7fffffff
#define TOSS(k) while(CSTOSS(k,cs.time)<=CS_KEY_MAX)
typedef struct
{
int seq;
unsigned long expire;
time_t atime;
time_t mtime;
Csid_t id;
} Auth_t;
typedef struct
{
dev_t dev;
ino_t ino;
} Fid_t;
struct Common_s;
typedef struct Common_s Common_t;
#define _CSS_FD_PRIVATE_ \
Css_t* css; \
int events; \
int set;
#define _CSS_PRIVATE_ \
Cssdisc_t* disc; \
Css_t* next; \
char buf[PATH_MAX]; \
char tmp[PATH_MAX]; \
int auth; \
int challenge; \
int fdpending; \
int fdpolling; \
int fdlistening; \
int fduser; \
Fid_t fid[2]; \
gid_t gid; \
uid_t uid; \
unsigned long newkey; \
unsigned long oldkey; \
unsigned long conkey; \
unsigned long timeout_last; \
unsigned long timeout_remain; \
unsigned long wakeup_last; \
unsigned long wakeup_remain;
#include <css.h>
struct Common_s
{
Css_t* servers;
Css_t* main;
Auth_t* auth;
int nauth;
Cspoll_t* fdpoll;
Cssfd_t* fdinfo;
unsigned long flags;
int fdpending;
int fdpolling;
int fdbefore;
int fdloop;
int fdnext;
int fdmax;
int pid;
int polling;
unsigned long expire;
};
#endif

View file

@ -1,130 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* return host status given name
*/
#include "cslib.h"
#include <proc.h>
static int
initiate(register Cs_t* state, const char* name, char* buf)
{
char* av[3];
if (!pathpath(CS_STAT_DAEMON, "", PATH_REGULAR|PATH_EXECUTE, buf, PATH_MAX))
{
messagef((state->id, NiL, -1, "stat: %s: %s: cannot find stat daemon", name, CS_STAT_DAEMON));
return -1;
}
av[0] = buf;
av[1] = (char*)name;
av[2] = 0;
procclose(procopen(av[0], av, NiL, NiL, 0));
return 0;
}
int
csstat(register Cs_t* state, const char* name, register Csstat_t* sp)
{
register int n;
register int i;
char* s;
unsigned long a;
unsigned long m;
struct stat st;
char buf[PATH_MAX];
static int init;
static char* dir;
messagef((state->id, NiL, -8, "stat(%s) call", name));
CSTIME();
if (!name || streq(name, CS_HOST_LOCAL))
name = (const char*)csname(state, 0);
if (!strchr(name, '/'))
{
if (!init)
{
init = 1;
if (pathpath(CS_STAT_DIR, "", PATH_EXECUTE, buf, sizeof(buf)))
dir = strdup(buf);
}
if (!dir)
return -1;
sfsprintf(buf, sizeof(buf), "%s/%s", dir, name);
if ((n = stat(buf, &st)) || (state->time - CS_STAT_DOWN) > (unsigned long)st.st_ctime)
{
if (initiate(state, name, buf))
return -1;
for (i = 1; i < CS_STAT_DOWN / 20; i <<= 1)
{
sleep(i);
if (!(n = stat(buf, &st)))
break;
}
if (n)
{
messagef((state->id, NiL, -1, "stat: %s: %s: stat error", name, buf));
return -1;
}
}
}
else
n = stat(name, &st);
if (n)
{
memzero(sp, sizeof(*sp));
sp->up = -CS_STAT_DOWN;
}
else
{
a = st.st_atime;
m = st.st_mtime;
if (!(sp->up = (((a >> 16) & 0x7ff) << ((a >> 27) & 0x1f))))
{
memzero(sp, sizeof(*sp));
sp->up = -(((a & 0x7ff) << ((a >> 11) & 0x1f)) + (long)(state->time - (unsigned long)st.st_ctime));
s = csname(state, 0);
if (streq(name, s))
initiate(state, name, buf);
}
else
{
sp->load = ((m >> 24) & 0xff) << 3;
sp->pctsys = (m >> 16) & 0xff;
sp->pctusr = (m >> 8) & 0xff;
sp->users = m & 0xff;
sp->idle = sp->users ? ((a & 0x7ff) << ((a >> 11) & 0x1f)) : ~0;
}
}
return 0;
}
int
_cs_stat(const char* name, Csstat_t* sp)
{
return csstat(&cs, name, sp);
}

View file

@ -1,75 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* write datagram
*/
#include "cslib.h"
ssize_t
csto(register Cs_t* state, int fd, const void* buf, size_t siz, Csaddr_t* addr)
{
#if CS_LIB_V10
struct udpaddr udp;
udp.host = addr->addr[0];
udp.port = addr->addr[1];
if (cswrite(state, fd, &udp, sizeof(udp)) != sizeof(udp))
{
messagef((state->id, NiL, -1, "to: %d: hdr write error", fd));
return -1;
}
return cswrite(state, fd, buf, siz);
#else
#if CS_LIB_SOCKET
struct sockaddr_in nam;
memzero(&nam, sizeof(nam));
nam.sin_family = AF_INET;
nam.sin_addr.s_addr = addr->addr[0];
nam.sin_port = addr->addr[1];
return sendto(fd, buf, siz, 0, (struct sockaddr*)&nam, sizeof(nam));
#else
errno = EINVAL;
messagef((state->id, NiL, -1, "to: %d: not supported", fd));
return -1;
#endif
#endif
}
ssize_t
_cs_to(int fd, const void* buf, size_t siz, Csaddr_t* addr)
{
return csto(&cs, fd, buf, siz, addr);
}

View file

@ -1,71 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* run time cs var support
*/
#include "cslib.h"
#ifndef TRUST
#define TRUST "/usr/local:/usr" /* trusted root dirs */
#endif
typedef struct
{
const char* name;
const char* trust;
const char* value;
} Var_t;
static Var_t var[] =
{
{ /* CS_VAR_LOCAL */ "CS_MOUNT_LOCAL", "/tmp/cs" },
{ /* CS_VAR_PROXY */ "CS_MOUNT_PROXY", "/dev/tcp/proxy/inet.proxy" },
{ /* CS_VAR_SHARE */ "CS_MOUNT_SHARE", "share/lib/cs" },
{ /* CS_VAR_TRUST */ "CS_MOUNT_TRUST", TRUST },
};
char*
csvar(Cs_t* state, int index, int trust)
{
register char* s;
register Var_t* p;
if (index < 0 || index >= elementsof(var))
return 0;
p = &var[index];
if (!p->name || trust)
return (char*)p->trust;
if (!p->value)
p->value = ((s = getenv(p->name)) && *s) ? (const char*)s : p->trust;
return (char*)p->value;
}
char*
_cs_var(int index, int trust)
{
return csvar(&cs, index, trust);
}

View file

@ -1,56 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* write n bytes to fd, using multiple write(2) if necessary
*/
#include "cslib.h"
ssize_t
cswrite(register Cs_t* state, int fd, const void* buf, register size_t n)
{
register char* p = (char*)buf;
register ssize_t i;
while (n > 0)
{
messagef((state->id, NiL, -9, "write(%d,%d) `%-.*s'", fd, n, n - 1, (n > 0 && *((char*)buf + n - 1) == '\n') ? (char*)buf : "..."));
if ((i = write(fd, p, n)) <= 0)
{
messagef((state->id, NiL, -9, "write(%d,%d) [%d]", fd, n, i));
if (i && p == (char*)buf)
return i;
break;
}
n -= i;
p += i;
}
return p - (char*)buf;
}
ssize_t
_cs_write(int fd, const void* buf, size_t n)
{
return cswrite(&cs, fd, buf, n);
}

View file

@ -1,153 +0,0 @@
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
#include <ast.h>
#include "FEATURE/lib"
#include <sys/types.h>
#if _hdr_poll
#include <poll.h>
#endif
#if _sys_socket && _mem_msg_control_msghdr
#include <sys/socket.h>
#ifdef SCM_RIGHTS
#undef SCM_RIGHTS
#else
#define SCM_RIGHTS 1
#endif
#endif
int
main()
{
register int m;
register int i;
sfprintf(sfstdout, "#define CS_REMOTE_SHELL \"%s\"\n", CS_REMOTE_SHELL);
sfprintf(sfstdout, "\n");
#if CS_LIB_SOCKET || CS_LIB_V10
sfprintf(sfstdout, "#define CS_TCP 1\n");
sfprintf(sfstdout, "#define CS_UDP 1\n");
#endif
#if CS_LIB_SOCKET_UN || CS_LIB_STREAM
sfprintf(sfstdout, "#define CS_FDP 1\n");
#endif
sfprintf(sfstdout, "\n");
#if _hdr_poll
#ifdef _nam_revents
sfprintf(sfstdout, "#define %s status\n", _nam_revents_str);
#else
sfprintf(sfstdout, "#define revents status\n");
#endif
sfprintf(sfstdout, "#include <poll.h>\n");
#ifdef _nam_revents
sfprintf(sfstdout, "#undef %s\n", _nam_revents_str);
#else
sfprintf(sfstdout, "#undef revents\n");
#endif
sfprintf(sfstdout, "\n");
sfprintf(sfstdout, "#define CS_POLL_CLOSE POLLHUP\n");
sfprintf(sfstdout, "#define CS_POLL_CONTROL POLLPRI\n");
sfprintf(sfstdout, "#define CS_POLL_ERROR POLLERR\n");
sfprintf(sfstdout, "#define CS_POLL_INVALID POLLNVAL\n");
sfprintf(sfstdout, "#define CS_POLL_READ POLLIN\n");
sfprintf(sfstdout, "#define CS_POLL_WRITE POLLOUT\n");
sfprintf(sfstdout, "\n");
m = 0;
#ifdef POLLIN
m |= POLLIN;
#endif
#ifdef POLLOUT
m |= POLLOUT;
#endif
#ifdef POLLPRI
m |= POLLPRI;
#endif
#ifdef POLLWRNORM
m |= POLLWRNORM;
#endif
#ifdef POLLRDNORM
m |= POLLRDNORM;
#endif
#ifdef POLLRDBAND
m |= POLLRDBAND;
#endif
#ifdef POLLWRBAND
m |= POLLWRBAND;
#endif
#ifdef POLLMSG
m |= POLLMSG;
#endif
#ifdef POLLSYNC
m |= POLLSYNC;
#endif
#ifdef POLLNVAL
m |= POLLNVAL;
#endif
#ifdef POLLERR
m |= POLLERR;
#endif
#ifdef POLLHUP
m |= POLLHUP;
#endif
#ifdef POLLNORM
m |= POLLNORM;
#endif
sfprintf(sfstdout, "#define CS_POLL_PSEUDO (CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_USER|CS_POLL_BEFORE)\n");
for (i = 0; m & (1<<i); i++);
sfprintf(sfstdout, "#define CS_POLL_AUTH (1<<%d)\n", i);
for (i++; m & (1<<i); i++);
sfprintf(sfstdout, "#define CS_POLL_CONNECT (1<<%d)\n", i);
for (i++; m & (1<<i); i++);
sfprintf(sfstdout, "#define CS_POLL_USER (1<<%d)\n", i);
for (i++; m & (1<<i); i++);
sfprintf(sfstdout, "#define CS_POLL_BEFORE (1<<%d)\n", i);
sfprintf(sfstdout, "\n");
sfprintf(sfstdout, "typedef struct pollfd Cspoll_t;\n");
#else
sfprintf(sfstdout, "#define CS_POLL_CLOSE (1<<0)\n");
sfprintf(sfstdout, "#define CS_POLL_CONTROL (1<<1)\n");
sfprintf(sfstdout, "#define CS_POLL_ERROR (1<<2)\n");
sfprintf(sfstdout, "#define CS_POLL_INVALID (1<<3)\n");
sfprintf(sfstdout, "#define CS_POLL_READ (1<<4)\n");
sfprintf(sfstdout, "#define CS_POLL_WRITE (1<<5)\n");
sfprintf(sfstdout, "\n");
sfprintf(sfstdout, "#define CS_POLL_PSEUDO (CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_USER|CS_POLL_BEFORE)\n");
sfprintf(sfstdout, "#define CS_POLL_AUTH (1<<6)\n");
sfprintf(sfstdout, "#define CS_POLL_CONNECT (1<<7)\n");
sfprintf(sfstdout, "#define CS_POLL_USER (1<<8)\n");
sfprintf(sfstdout, "#define CS_POLL_BEFORE (1<<9)\n");
sfprintf(sfstdout, "\n");
sfprintf(sfstdout, "typedef struct\n");
sfprintf(sfstdout, "{\n");
sfprintf(sfstdout, " short fd;\n");
sfprintf(sfstdout, " unsigned char events;\n");
sfprintf(sfstdout, " unsigned char status;\n");
sfprintf(sfstdout, "} Cspoll_t;\n");
#endif
#ifdef SCM_RIGHTS
sfprintf(sfstdout, "\n#define SCM_RIGHTS %d\n", SCM_RIGHTS);
#endif
exit(0);
}

View file

@ -1,103 +0,0 @@
hdr netdb,stropts,netinet/in,netinet/tcp
lib fattach,getdtablesize,gethostname,getrlimit,sigblock,uname
lib recvmsg,sendmsg
lib ntohs,ntohl,htons,htonl sys/types.h sys/socket.h netinet/in.h
mem statvfs.f_fstr sys/types.h sys/statvfs.h
mem msghdr.msg_accrights sys/types.h sys/uio.h sys/socket.h
mem msghdr.msg_control sys/types.h sys/uio.h sys/socket.h
mem msghdr.msg_flags sys/types.h sys/uio.h sys/socket.h
mem utsname.nodeext sys/utsname.h
sym revents sys/types.h poll.h
sys file,inet/tcp_user,resource,select,socket,sockio,uio,un,utsname
tst stream_pipe note{ pipes are streams }end execute{
#include <sys/types.h>
#include <stropts.h>
_BEGIN_EXTERNS_
extern int pipe _ARG_((int*));
_END_EXTERNS_
main()
{ struct strpeek pbuf;
int fds[2];
if (pipe(fds)) return 1;
pbuf.flags = 0;
pbuf.ctlbuf.maxlen = pbuf.databuf.maxlen =
pbuf.ctlbuf.len = pbuf.databuf.len = 0;
pbuf.ctlbuf.buf = pbuf.databuf.buf = 0;
return ioctl(fds[0],I_PEEK,&pbuf) < 0;
}
}end
tst tst_rsh run{
: remote shell
path=`echo $PATH:/usr/add-on/ucb/bin:/usr/add-on/bsd/bin:/usr/ucb:/usr/bsd | sed 's/:/ /g'`
rsh=ssh
hostname=`exec 2>/dev/null && hostname || uname -n || cat /etc/whoami || echo local`
for b in ssh rsh remsh
do for d in $path
do if test -x $d/$b
then case $b in
rsh) case `$d/$b $hostname echo ok 2>/dev/null & sleep 5` in
ok) ;;
*) continue ;;
esac
;;
esac
rsh=$d/$b
break 2
fi
done
done
echo '#define CS_REMOTE_SHELL ''"'$rsh'" /* remote shell path */'
}end
tst compile{
#include <sys/types.h>
#include <sys/socket.h>
int f()
{
int len;
struct sockaddr sa;
return getsockname(0, &sa, &len);
}
}end pass{
echo 'typedef int Sock_size_t;'
}end fail{
echo 'typedef size_t Sock_size_t;'
}end
tst cat{
#if _sys_inet_tcp_user
#define CS_LIB_V10 1
#else
#if _sys_socket && _hdr_netdb
#define CS_LIB_SOCKET 1
#if _sys_un
#define CS_LIB_SOCKET_UN 1
#if _mem_msg_accrights_msghdr && ! _mem_msg_flags_msghdr
#undef _mem_msg_control_msghdr
#endif
#if _lib_recvmsg && _lib_sendmsg && ( _mem_msg_accrights_msghdr || _mem_msg_control_msghdr )
#define CS_LIB_SOCKET_RIGHTS 1
#endif
#endif
#endif
#if _hdr_stropts && _lib_fattach && _stream_pipe
#define CS_LIB_STREAM 1
#endif
#endif
#if !_sys_statvfs
#define _mem_f_fstr_statvfs 1
#define _mem_f_fsid_statvfs 1
#endif
}end
tst mem_f_fsid_statvfs compile{
#include <sys/types.h>
#include <sys/statvfs.h>
int foo()
{
struct statvfs fs;
fs.f_fsid = 0;
}
}end

View file

@ -1,2 +0,0 @@
hdr termios
lib tcgetattr,tcsetattr

View file

@ -1,275 +0,0 @@
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1990-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# http://www.eclipse.org/org/documents/epl-v10.html #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# Glenn Fowler <gsf@research.att.com> #
# #
########################################################################
: generate local host info
#
# genlocal [options] [host ...]
#
# @(#)genlocal (AT&T Research) 2002-10-02
#
# NOTE: this only works for hosts the caller can reach by rsh/ssh
#
case $RANDOM in
$RANDOM) exec ksh $0 "$@"; echo "$0: ksh required" >&2; exit 1 ;;
esac
integer cluster=5
dir=.
file=
heading=1
list=
rsh=rsh
timeout=90
verbose=:
while :
do case $# in
0) break ;;
esac
case $1 in
-[frt])case $# in
1) set -- '-?'
break
;;
esac
case $1 in
-f) file=$2 ;;
-r) rsh=$2 ;;
-t) timeout=$2 ;;
esac
shift
;;
-h) heading=
;;
-n) list=1
;;
-v) verbose='print -u2'
;;
'-?') break
;;
[-+]*) print -u2 "$0: $1: invalid option"
set -- '-?'
break
;;
*) break
;;
esac
shift
done
case $1 in
'-?') print -u2 "Usage: $0 [-hnv] [-f share-file] [-r rsh-path] [-t timeout] [host ...]"; exit 1 ;;
esac
case $file in
"") ifs=${IFS-'
'}
IFS=:
set "" $PATH "--" "$@"
IFS=$ifs
f=lib/cs/share
while :
do shift
case $1 in
"") continue ;;
--) break ;;
esac
case $file in
"") test -f ${1%bin}$f && file=${1%bin}$f ;;
esac
done
shift
case $file in
"") print -u2 $0: $f: not found; exit 1 ;;
esac
;;
*) if test ! -f $file
then print -u2 "$0: $file: cannot read share file"; exit 1
fi
;;
esac
print -u2 "$0: warning: $rsh may hang on some hosts -- monitor the progress with the -v option or ps $$"
server=
for host in $(egrep -v '^#' $file)
do case $server in
"") server=$host ;;
*) server="$server|$host" ;;
esac
done
hostname=$(package host name)
hostname=${hostname%%.*}
case $# in
0) domain=$(
{
cat /etc/hosts
ypcat hosts
} 2>/dev/null |
egrep "[^#].*[ ]$hostname(\$|[. ])" |
sed -e '1!d' -e 's/^[^ ]*//' -e 's/[^.]*.//' -e 's/[ ].*//'
)
set -- $(
{
print "$hostname"
egrep -v '^#' $file
ruptime | fgrep -v 'no hosts'
{
for i in /etc/resolv.conf /usr/etc/resolv.conf
do if test -f $i
then echo "ls -t A $(sed -e '/^domain/!d' -e 's/.*[ ][ ]*//' $i)" | nslookup
break
fi
done
cat /etc/hosts
ypcat hosts
} |
fgrep ".$domain" |
awk '{print $2}'
} 2>/dev/null |
sed -e 's/[. ].*//' -e '/^[a-zA-Z].*[a-zA-Z0-9]$/!d' |
sort -u
)
case $list in
?*) print domain=$domain
;;
esac
;;
esac
case $list in
?*) print hosts='"'$*'"'; exit ;;
esac
hosts=
for host
do case $host in
local|localhost) host=$hostname ;;
esac
case " $hosts " in
*" $host "*) continue ;;
esac
hosts="$hosts $host"
$verbose -n "$host "
case $host in
$hostname)
package host name type cpu rating
;;
*) if ping -c 1 -w 4 $host >/dev/null 2>&1
then $rsh $host bin/package host name type cpu rating &
info=$!
{
sleep $timeout
kill -9 $info
} &
time=$!
wait $info
kill -9 $time
fi
;;
esac 2>/dev/null
done | while read host type cpu rating
do $verbose type=$type cpu=$cpu rating=$rating
host=${host%%.*}
eval "case '$host' in
$server) idle= ;;
*) idle=15m ;;
esac"
print $host" "type=$type" "${rating}${idle:+" idle=$idle"}${cpu:+" cpu=$cpu"}
done | sort -b +2n -3 | {
integer v c d i j k n
((n=0))
while read host type rate attr
do ((n=n+1))
h[n]=$host
t[n]=$type
v[n]=$rate
a[n]=$attr
done
c=1
while ((c))
do ((c=0))
((i=1))
while ((i<n))
do ((d=v[i+1]-v[i]))
if ((d>1&&d<cluster))
then ((d=d/2))
((v[i]=v[i]+d))
((v[i+1]=v[i+1]-d))
c=1
fi
((i=i+1))
done
done
((i=1))
while ((i<=n))
do ((c=v[i]))
((j=i+1))
((k=1))
while ((j<=n))
do if (((v[j]-v[j-1])>1||(v[j]-v[i])>cluster))
then break
fi
((c=c+v[j]))
((k=k+1))
((j=j+1))
done
((c=c/k))
((d=c%10))
((c=c-d))
if ((d>6))
then ((c=c+10))
elif ((d>3))
then ((c=c+5))
fi
while ((i<j))
do ((v[i]=c))
((i=i+1))
done
done
((i=1))
while ((i<=n))
do rate=${v[i]}
print ${h[i]} ${t[i]} rating=${v[i]}" ${a[i]}"
((i=i+1))
done
} | sort -b +1 -2 +2.7n -3 +0 -1 | while read host type attr
do case $heading in
1) print '#'
print '# local host attributes'
print '#'
print
print 'local busy=2m pool=9'
print
;;
''|$type)
;;
*) print
;;
esac
heading=$type
case $host in
????????*)
tab1=" "
;;
*) tab1=" "
;;
esac
case $type in
????????*)
tab2=" "
;;
*) tab2=" "
;;
esac
print $host"$tab1"$type"$tab2$attr"
done

View file

@ -1,88 +0,0 @@
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1990-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# http://www.eclipse.org/org/documents/epl-v10.html #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# Glenn Fowler <gsf@research.att.com> #
# #
########################################################################
: generate list of file servers
#
# genshare [options]
#
# @(#)genshare (AT&T Research) 2002-10-02
#
dir=.
rsh=rsh
while :
do case $# in
0) break ;;
esac
case $1 in
-[dr]) case $# in
1) set -- '-?'
break
;;
esac
case $1 in
-d) dir=$2 ;;
-r) rsh=$2 ;;
esac
shift
;;
'-?') break
;;
[-+]*) echo "$0: $1: invalid option" >&2
set -- '-?'
break
;;
*) break
;;
esac
shift
done
case $1 in
?*) echo "Usage: $0 [-d share-dir] [-r rsh-path]" >&2; exit 1 ;;
esac
if test ! -d $dir
then echo "$0: $dir: invalid directory" >&2; exit 1
fi
s="`df 2>/dev/null | sed -e 's/^[^(]*(//' -e '/^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*:/!d' -e 's/:.*//' -e '/^.$/d' | sort -u`"
case $s in
"") s=`hostname 2>/dev/null || uname -n 2>/dev/null || cat /etc/whoami 2>/dev/null || echo local 2>/dev/null`
;;
*) p=`df $dir/. 2>/dev/null | sed -e 's/^[^(]*(//' -e '/^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*:/!d' -e 's/:.*//' -e '/^.$/d'`
case $p in
"") p=`hostname 2>/dev/null || uname -n 2>/dev/null || cat /etc/whoami 2>/dev/null || echo local 2>/dev/null` ;;
esac
t=$s
s=$p
for h in $t
do case $s in
*$h*) ;;
*) s="$s
$h" ;;
esac
done
t=$s
s=`(echo "$t"; for h in $t
do $rsh $h df '2>/dev/null' | sed -e 's/^[^(]*(//' -e '/^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*:/!d' -e 's/:.*//'
done) | sort | uniq -c | sort -bnr | sed -e 's/^[ ]*[0-9]*[ ]*//'`
;;
esac
echo '#'
echo '# local file servers'
echo '#'
echo "$s"

View file

@ -1,85 +0,0 @@
#
# classic advanced software technology department local host attributes
# @(#)local.ast (AT&T Bell Laboratories) 07/04/95
#
local busy=2m pool=9
#
# servers
#
gryphon type=sun4 rating=20 cpu=3 os=solbourne
toucan type=sun4 rating=21 cpu=4
got type=sol.sun4 rating=35 cpu=4 os=2.4
lynx type=hp.pa rating=43
swift type=sgi.mips2 rating=95 cpu=4
#
# sparc 20
#
jacana type=sol.sun4 rating=42 idle=15m os=2.4
pelican type=sol.sun4 rating=42 idle=15m
#
# sparc 10
#
dodo type=sun4 rating=30 idle=15m
#
# sparc 5
#
drake type=sol.sun4 rating=30 idle=15m os=2.3
peregrine type=sol.sun4 rating=30 idle=15m os=5.5
#
# sparc 2
#
kiwi type=5e.sol.sun4 rating=22 idle=15m os=2.4
condor type=sun4 rating=22 idle=15m
early type=sun4 rating=22 idle=15m
roc type=sun4 rating=22 idle=15m
#
# sparc 1+
#
anton type=sun4 rating=12 idle=15m
bluejay type=sun4 rating=12 idle=15m
callisto type=sun4 rating=12 idle=15m
sylvia type=sun4 rating=12 idle=15m
#kakapo type=sun4 rating=12 idle=15m
#
# sparc 1
#
avocet type=sun4 rating=10 idle=15m
cardinal type=sun4 rating=10 idle=15m
duck type=sun4 rating=10 idle=15m
kite type=sun4 rating=10 idle=15m
parrot type=sun4 rating=10 idle=15m
robin type=sun4 rating=10 idle=15m
#emu type=sun4 rating=10 idle=15m
#cuckoo type=sun4 rating=10 idle=15m
#mynah type=sun4 rating=10 idle=15m
#paloma type=sun4 rating=10 idle=15m
#falcon type=sol.sun4 rating=10 idle=15m
#
# sgi R3000
#
#quetzal type=sgi.mips rating=13 idle=15m
#
# sgi R4000 IP22
#
daffy type=sgi.mips2 rating=95 idle=15m os=irix-5.3
daytona type=sgi.mips2 rating=95 idle=15m
flicker type=sgi.mips2 rating=95 idle=15m
nithack type=sgi.mips2 rating=127 idle=15m os=irix-5.3
rosella type=sgi.mips2 rating=95 idle=15m
htron type=sgi.mips2 rating=63 idle=15m os=irix-5.3
wren type=sgi.mips2 rating=63 idle=15m os=irix-5.3
#
# sgi R4000 IP20
#
guan type=sgi.mips2 rating=63 idle=15m
nighthawk type=sgi.mips2 rating=63 idle=15m
nightjar type=sgi.mips2 rating=63 idle=15m
tweety type=sgi.mips2 rating=63 idle=15m
#
# bsd i386
#
panda type=bsd.i386 rating=12 idle=15m
#
# att 386
#
quail type=att.i386 rating=10 idle=15m

Some files were not shown because too many files have changed in this diff Show more