This commit was manufactured by cvs2svn to create branch 'RELENG_6'.

This commit is contained in:
cvs2svn 2007-01-26 10:19:09 +00:00
parent 473caab65c
commit 7fc74e4ad3
63 changed files with 20863 additions and 0 deletions

View File

@ -0,0 +1,176 @@
#
# Makefile template for rlfe
#
# See machine dependant config.h for more configuration options.
#
srcdir = @srcdir@
VPATH = @srcdir@
DESTDIR =
# Where to install screen.
prefix = @prefix@
exec_prefix = @exec_prefix@
# don't forget to change mandir and infodir in doc/Makefile.
bindir = $(exec_prefix)/bin
VERSION = @VERSION@
SCREEN = screen-$(VERSION)
CC = @CC@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
#LDFLAGS = -L$(READLINE_DIR)
LDFLAGS = @LDFLAGS@
LIBS = -lreadline -lhistory -lncurses @LIBS@
CPP=@CPP@
CPP_DEPEND=$(CC) -MM
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
AWK = @AWK@
OPTIONS=
#OPTIONS= -DDEBUG
SHELL=/bin/sh
CFILES= rlfe.c pty.c
HFILES= extern.h os.h screen.h
EXTRA_DIST=configure.in configure Makefile.in config.h.in ChangeLog README
OFILES= rlfe.o pty.o
all: rlfe
rlfe: $(OFILES)
$(CC) $(LDFLAGS) -o $@ $(OFILES) $(LIBS)
rlfe-$(VERSION).tar.gz:
tar czf $@ $(CFILES) $(HFILES) $(EXTRA_DIST)
.c.o:
$(CC) -c -I. -I$(srcdir) $(M_CFLAGS) $(DEFS) $(OPTIONS) $(CFLAGS) $<
install_bin: .version screen
-if [ -f $(DESTDIR)$(bindir)/$(SCREEN) ] && [ ! -f $(DESTDIR)$(bindir)/$(SCREEN).old ]; \
then mv $(DESTDIR)$(bindir)/$(SCREEN) $(DESTDIR)$(bindir)/$(SCREEN).old; fi
$(INSTALL_PROGRAM) screen $(DESTDIR)$(bindir)/$(SCREEN)
-chown root $(DESTDIR)$(bindir)/$(SCREEN) && chmod 4755 $(DESTDIR)$(bindir)/$(SCREEN)
# This doesn't work if $(bindir)/screen is a symlink
-if [ -f $(DESTDIR)$(bindir)/screen ] && [ ! -f $(DESTDIR)$(bindir)/screen.old ]; then mv $(DESTDIR)$(bindir)/screen $(DESTDIR)$(bindir)/screen.old; fi
rm -f $(DESTDIR)$(bindir)/screen
(cd $(DESTDIR)$(bindir) && ln -sf $(SCREEN) screen)
cp $(srcdir)/utf8encodings/?? $(DESTDIR)$(SCREENENCODINGS)
uninstall: .version
rm -f $(DESTDIR)$(bindir)/$(SCREEN)
rm -f $(DESTDIR)$(bindir)/screen
-mv $(DESTDIR)$(bindir)/screen.old $(DESTDIR)$(bindir)/screen
rm -f $(DESTDIR)$(ETCSCREENRC)
cd doc; $(MAKE) uninstall
shadow:
mkdir shadow;
cd shadow; ln -s ../*.[ch] ../*.in ../*.sh ../configure ../doc ../terminfo ../etc .
rm -f shadow/term.h shadow/tty.c shadow/comm.h shadow/osdef.h
echo "install all Makefiles and config:" > shadow/Makefile
echo " rm -f config.cache" >> shadow/Makefile
echo " sh ./configure" >> shadow/Makefile
term.h: term.c term.sh
AWK=$(AWK) srcdir=$(srcdir) sh $(srcdir)/term.sh
kmapdef.c: term.h
tty.c: tty.sh
sh $(srcdir)/tty.sh tty.c
mostlyclean:
rm -f $(OFILES) rlfe *.o
clean celan: mostlyclean
rm -f tty.c term.h comm.h osdef.h kmapdef.c core
# Delete all files from the current directory that are created by
# configuring or building the program.
# building of term.h/comm.h requires awk. Keep it in the distribution
# we keep config.h, as this file knows where 'make dist' finds the ETCSCREENRC.
#distclean: mostlyclean
# rm -f $(SCREEN).tar $(SCREEN).tar.gz
# rm -f config.status Makefile
# rm -f osdef.h doc/Makefile
maintainer-clean:
@echo "This command is not even intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
# Delete everything from the current directory that can be
# reconstructed with this Makefile.
realclean: .version mostlyclean
rm -f $(SCREEN).tar $(SCREEN).tar.gz
rm -f config.status Makefile doc/Makefile
rm -f tty.c term.h comm.h osdef.h kmapdef.c
rm -f config.h
echo "install all Makefiles and config:" > Makefile
echo " sh ./configure" >> Makefile
tags TAGS: $(CFILES)
-ctags *.sh $(CFILES) *.h
-ctags -e *.sh $(CFILES) *.h
dist: .version $(SCREEN).tar.gz
# Perform self-tests (if any).
check:
config:
rm -f config.cache
sh ./configure
###############################################################################
.version:
@rev=`sed < $(srcdir)/patchlevel.h -n -e '/#define REV/s/#define REV *//p'`; \
vers=`sed < $(srcdir)/patchlevel.h -n -e '/#define VERS/s/#define VERS *//p'`; \
pat=`sed < $(srcdir)/patchlevel.h -n -e '/#define PATCHLEVEL/s/#define PATCHLEVEL *//p'`; \
if [ "$${rev}.$${vers}.$${pat}" != "$(VERSION)" ]; then \
echo "This distribution is screen-$${rev}.$${vers}.$${pat}, but"; \
echo "the Makefile is from $(VERSION). Please update!"; exit 1; fi
###############################################################################
mdepend: $(CFILES) term.h
@rm -f DEPEND ; \
for i in ${CFILES} ; do \
echo "$$i" ; \
echo `echo "$$i" | sed -e 's/.c$$/.o/'`": $$i" `\
cc -E $$i |\
grep '^# .*"\./.*\.h"' |\
(sort -t'"' -u -k 2,2 2>/dev/null || sort -t'"' -u +1 -2) |\
sed -e 's/.*"\.\/\(.*\)".*/\1/'\
` >> DEPEND ; \
done
depend: depend.in
./config.status || ./configure
depend.in: $(CFILES) term.h
cp Makefile.in Makefile.in~
sed -e '/\#\#\# Dependencies/q' < Makefile.in > tmp_make
for i in $(CFILES); do echo $$i; $(CPP_DEPEND) $$i >> tmp_make; done
mv tmp_make Makefile.in
###############################################################################
### Dependencies:
pty.o: pty.c config.h

38
contrib/ncurses/AUTHORS Normal file
View File

@ -0,0 +1,38 @@
-------------------------------------------------------------------------------
-- Copyright (c) 2006 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell copies --
-- of the Software, and to permit persons to whom the Software is furnished --
-- to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN --
-- NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE --
-- USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
-------------------------------------------------------------------------------
-- $Id: AUTHORS,v 1.2 2006/10/28 21:44:52 tom Exp $
-------------------------------------------------------------------------------
These are the principal authors/contributors of ncurses since 1.9.9e,
in decreasing order of their contribution:
TD Thomas E. Dickey
JPF Juergen Pfeifer
ESR Eric S Raymond
AVL Alexander V Lukyanov
PB Philippe Blain
SV Sven Verdoolaege

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
/****************************************************************************
* Copyright (c) 2004 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey *
****************************************************************************/
#include "form.priv.h"
MODULE_ID("$Id: f_trace.c,v 1.1 2004/12/25 23:28:49 tom Exp $")
NCURSES_EXPORT(FIELD **)
_nc_retrace_field_ptr(FIELD **code)
{
T((T_RETURN("%p"), code));
return code;
}
NCURSES_EXPORT(FIELD *)
_nc_retrace_field(FIELD *code)
{
T((T_RETURN("%p"), code));
return code;
}
NCURSES_EXPORT(FIELDTYPE *)
_nc_retrace_field_type(FIELDTYPE *code)
{
T((T_RETURN("%p"), code));
return code;
}
NCURSES_EXPORT(FORM *)
_nc_retrace_form(FORM *code)
{
T((T_RETURN("%p"), code));
return code;
}
NCURSES_EXPORT(Form_Hook)
_nc_retrace_form_hook(Form_Hook code)
{
T((T_RETURN("%p"), code));
return code;
}

View File

@ -0,0 +1,740 @@
/****************************************************************************
* Copyright (c) 2002,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 2002,2005 *
****************************************************************************/
/* LINTLIBRARY */
/* ./f_trace.c */
#include "form.priv.h"
#undef _nc_retrace_field_ptr
FIELD **_nc_retrace_field_ptr(
FIELD **code)
{ return(*(FIELD ***)0); }
#undef _nc_retrace_field
FIELD *_nc_retrace_field(
FIELD *code)
{ return(*(FIELD **)0); }
#undef _nc_retrace_field_type
FIELDTYPE *_nc_retrace_field_type(
FIELDTYPE *code)
{ return(*(FIELDTYPE **)0); }
#undef _nc_retrace_form
FORM *_nc_retrace_form(
FORM *code)
{ return(*(FORM **)0); }
#undef _nc_retrace_form_hook
Form_Hook _nc_retrace_form_hook(
Form_Hook code)
{ return(*(Form_Hook *)0); }
/* ./fld_arg.c */
#undef set_fieldtype_arg
int set_fieldtype_arg(
FIELDTYPE *typ,
void *(*const make_arg)(
va_list *p1),
void *(*const copy_arg)(
const void *p1),
void (*const free_arg)(
void *p1))
{ return(*(int *)0); }
#undef field_arg
void *field_arg(
const FIELD *field)
{ return(*(void **)0); }
/* ./fld_attr.c */
#undef set_field_fore
int set_field_fore(
FIELD *field,
chtype attr)
{ return(*(int *)0); }
#undef field_fore
chtype field_fore(
const FIELD *field)
{ return(*(chtype *)0); }
#undef set_field_back
int set_field_back(
FIELD *field,
chtype attr)
{ return(*(int *)0); }
#undef field_back
chtype field_back(
const FIELD *field)
{ return(*(chtype *)0); }
/* ./fld_current.c */
#undef set_current_field
int set_current_field(
FORM *form,
FIELD *field)
{ return(*(int *)0); }
#undef current_field
FIELD *current_field(
const FORM *form)
{ return(*(FIELD **)0); }
#undef field_index
int field_index(
const FIELD *field)
{ return(*(int *)0); }
/* ./fld_def.c */
#undef _nc_Default_Field
FIELD *_nc_Default_Field;
#undef _nc_Make_Argument
TypeArgument *_nc_Make_Argument(
const FIELDTYPE *typ,
va_list *ap,
int *err)
{ return(*(TypeArgument **)0); }
#undef _nc_Copy_Argument
TypeArgument *_nc_Copy_Argument(
const FIELDTYPE *typ,
const TypeArgument *argp,
int *err)
{ return(*(TypeArgument **)0); }
#undef _nc_Free_Argument
void _nc_Free_Argument(
const FIELDTYPE *typ,
TypeArgument *argp)
{ /* void */ }
#undef _nc_Copy_Type
NCURSES_BOOL _nc_Copy_Type(
FIELD *dst,
FIELD const *src)
{ return(*(NCURSES_BOOL *)0); }
#undef _nc_Free_Type
void _nc_Free_Type(
FIELD *field)
{ /* void */ }
#undef new_field
FIELD *new_field(
int rows,
int cols,
int frow,
int fcol,
int nrow,
int nbuf)
{ return(*(FIELD **)0); }
#undef free_field
int free_field(
FIELD *field)
{ return(*(int *)0); }
/* ./fld_dup.c */
#undef dup_field
FIELD *dup_field(
FIELD *field,
int frow,
int fcol)
{ return(*(FIELD **)0); }
/* ./fld_ftchoice.c */
#undef set_fieldtype_choice
int set_fieldtype_choice(
FIELDTYPE *typ,
NCURSES_BOOL (*const next_choice)(
FIELD *p1,
const void *p2),
NCURSES_BOOL (*const prev_choice)(
FIELD *p1,
const void *p2))
{ return(*(int *)0); }
/* ./fld_ftlink.c */
#undef link_fieldtype
FIELDTYPE *link_fieldtype(
FIELDTYPE *type1,
FIELDTYPE *type2)
{ return(*(FIELDTYPE **)0); }
/* ./fld_info.c */
#undef field_info
int field_info(
const FIELD *field,
int *rows,
int *cols,
int *frow,
int *fcol,
int *nrow,
int *nbuf)
{ return(*(int *)0); }
#undef dynamic_field_info
int dynamic_field_info(
const FIELD *field,
int *drows,
int *dcols,
int *maxgrow)
{ return(*(int *)0); }
/* ./fld_just.c */
#undef set_field_just
int set_field_just(
FIELD *field,
int just)
{ return(*(int *)0); }
#undef field_just
int field_just(
const FIELD *field)
{ return(*(int *)0); }
/* ./fld_link.c */
#undef link_field
FIELD *link_field(
FIELD *field,
int frow,
int fcol)
{ return(*(FIELD **)0); }
/* ./fld_max.c */
#undef set_max_field
int set_max_field(
FIELD *field,
int maxgrow)
{ return(*(int *)0); }
/* ./fld_move.c */
#undef move_field
int move_field(
FIELD *field,
int frow,
int fcol)
{ return(*(int *)0); }
/* ./fld_newftyp.c */
#undef _nc_Default_FieldType
const FIELDTYPE *_nc_Default_FieldType = {0};
#undef new_fieldtype
FIELDTYPE *new_fieldtype(
NCURSES_BOOL (*const field_check)(
FIELD *p1,
const void *p2),
NCURSES_BOOL (*const char_check)(
int p1,
const void *p2))
{ return(*(FIELDTYPE **)0); }
#undef free_fieldtype
int free_fieldtype(
FIELDTYPE *typ)
{ return(*(int *)0); }
/* ./fld_opts.c */
#undef set_field_opts
int set_field_opts(
FIELD *field,
Field_Options opts)
{ return(*(int *)0); }
#undef field_opts
Field_Options field_opts(
const FIELD *field)
{ return(*(Field_Options *)0); }
#undef field_opts_on
int field_opts_on(
FIELD *field,
Field_Options opts)
{ return(*(int *)0); }
#undef field_opts_off
int field_opts_off(
FIELD *field,
Field_Options opts)
{ return(*(int *)0); }
/* ./fld_pad.c */
#undef set_field_pad
int set_field_pad(
FIELD *field,
int ch)
{ return(*(int *)0); }
#undef field_pad
int field_pad(
const FIELD *field)
{ return(*(int *)0); }
/* ./fld_page.c */
#undef set_new_page
int set_new_page(
FIELD *field,
NCURSES_BOOL new_page_flag)
{ return(*(int *)0); }
#undef new_page
NCURSES_BOOL new_page(
const FIELD *field)
{ return(*(NCURSES_BOOL *)0); }
/* ./fld_stat.c */
#undef set_field_status
int set_field_status(
FIELD *field,
NCURSES_BOOL status)
{ return(*(int *)0); }
#undef field_status
NCURSES_BOOL field_status(
const FIELD *field)
{ return(*(NCURSES_BOOL *)0); }
/* ./fld_type.c */
#undef set_field_type
int set_field_type(
FIELD *field,
FIELDTYPE *type,
...)
{ return(*(int *)0); }
#undef field_type
FIELDTYPE *field_type(
const FIELD *field)
{ return(*(FIELDTYPE **)0); }
/* ./fld_user.c */
#undef set_field_userptr
int set_field_userptr(
FIELD *field,
void *usrptr)
{ return(*(int *)0); }
#undef field_userptr
void *field_userptr(
const FIELD *field)
{ return(*(void **)0); }
/* ./frm_cursor.c */
#undef pos_form_cursor
int pos_form_cursor(
FORM *form)
{ return(*(int *)0); }
/* ./frm_data.c */
#undef data_behind
NCURSES_BOOL data_behind(
const FORM *form)
{ return(*(NCURSES_BOOL *)0); }
#undef data_ahead
NCURSES_BOOL data_ahead(
const FORM *form)
{ return(*(NCURSES_BOOL *)0); }
/* ./frm_def.c */
#undef _nc_Default_Form
FORM *_nc_Default_Form;
#undef new_form
FORM *new_form(
FIELD **fields)
{ return(*(FORM **)0); }
#undef free_form
int free_form(
FORM *form)
{ return(*(int *)0); }
#undef set_form_fields
int set_form_fields(
FORM *form,
FIELD **fields)
{ return(*(int *)0); }
#undef form_fields
FIELD **form_fields(
const FORM *form)
{ return(*(FIELD ***)0); }
#undef field_count
int field_count(
const FORM *form)
{ return(*(int *)0); }
/* ./frm_driver.c */
#undef _nc_Position_Form_Cursor
int _nc_Position_Form_Cursor(
FORM *form)
{ return(*(int *)0); }
#undef _nc_Refresh_Current_Field
int _nc_Refresh_Current_Field(
FORM *form)
{ return(*(int *)0); }
#undef _nc_Synchronize_Attributes
int _nc_Synchronize_Attributes(
FIELD *field)
{ return(*(int *)0); }
#undef _nc_Synchronize_Options
int _nc_Synchronize_Options(
FIELD *field,
Field_Options newopts)
{ return(*(int *)0); }
#undef _nc_Set_Current_Field
int _nc_Set_Current_Field(
FORM *form,
FIELD *newfield)
{ return(*(int *)0); }
#undef _nc_Internal_Validation
NCURSES_BOOL _nc_Internal_Validation(
FORM *form)
{ return(*(NCURSES_BOOL *)0); }
#undef _nc_First_Active_Field
FIELD *_nc_First_Active_Field(
FORM *form)
{ return(*(FIELD **)0); }
#undef _nc_Set_Form_Page
int _nc_Set_Form_Page(
FORM *form,
int page,
FIELD *field)
{ return(*(int *)0); }
typedef struct
{
int keycode;
int (*cmd) (FORM *);
}
Binding_Info;
#undef form_driver
int form_driver(
FORM *form,
int c)
{ return(*(int *)0); }
#undef set_field_buffer
int set_field_buffer(
FIELD *field,
int buffer,
const char *value)
{ return(*(int *)0); }
#undef field_buffer
char *field_buffer(
const FIELD *field,
int buffer)
{ return(*(char **)0); }
#undef _nc_Widen_String
wchar_t *_nc_Widen_String(
char *source,
int *lengthp)
{ return(*(wchar_t **)0); }
/* ./frm_hook.c */
#undef set_field_init
int set_field_init(
FORM *form,
Form_Hook func)
{ return(*(int *)0); }
#undef field_init
Form_Hook field_init(
const FORM *form)
{ return(*(Form_Hook *)0); }
#undef set_field_term
int set_field_term(
FORM *form,
Form_Hook func)
{ return(*(int *)0); }
#undef field_term
Form_Hook field_term(
const FORM *form)
{ return(*(Form_Hook *)0); }
#undef set_form_init
int set_form_init(
FORM *form,
Form_Hook func)
{ return(*(int *)0); }
#undef form_init
Form_Hook form_init(
const FORM *form)
{ return(*(Form_Hook *)0); }
#undef set_form_term
int set_form_term(
FORM *form,
Form_Hook func)
{ return(*(int *)0); }
#undef form_term
Form_Hook form_term(
const FORM *form)
{ return(*(Form_Hook *)0); }
/* ./frm_opts.c */
#undef set_form_opts
int set_form_opts(
FORM *form,
Form_Options opts)
{ return(*(int *)0); }
#undef form_opts
Form_Options form_opts(
const FORM *form)
{ return(*(Form_Options *)0); }
#undef form_opts_on
int form_opts_on(
FORM *form,
Form_Options opts)
{ return(*(int *)0); }
#undef form_opts_off
int form_opts_off(
FORM *form,
Form_Options opts)
{ return(*(int *)0); }
/* ./frm_page.c */
#undef set_form_page
int set_form_page(
FORM *form,
int page)
{ return(*(int *)0); }
#undef form_page
int form_page(
const FORM *form)
{ return(*(int *)0); }
/* ./frm_post.c */
#undef post_form
int post_form(
FORM *form)
{ return(*(int *)0); }
#undef unpost_form
int unpost_form(
FORM *form)
{ return(*(int *)0); }
/* ./frm_req_name.c */
#undef form_request_name
const char *form_request_name(
int request)
{ return(*(const char **)0); }
#undef form_request_by_name
int form_request_by_name(
const char *str)
{ return(*(int *)0); }
/* ./frm_scale.c */
#undef scale_form
int scale_form(
const FORM *form,
int *rows,
int *cols)
{ return(*(int *)0); }
/* ./frm_sub.c */
#undef set_form_sub
int set_form_sub(
FORM *form,
WINDOW *win)
{ return(*(int *)0); }
#undef form_sub
WINDOW *form_sub(
const FORM *form)
{ return(*(WINDOW **)0); }
/* ./frm_user.c */
#undef set_form_userptr
int set_form_userptr(
FORM *form,
void *usrptr)
{ return(*(int *)0); }
#undef form_userptr
void *form_userptr(
const FORM *form)
{ return(*(void **)0); }
/* ./frm_win.c */
#undef set_form_win
int set_form_win(
FORM *form,
WINDOW *win)
{ return(*(int *)0); }
#undef form_win
WINDOW *form_win(
const FORM *form)
{ return(*(WINDOW **)0); }
/* ./fty_alnum.c */
typedef struct
{
int width;
}
alnumARG;
#undef TYPE_ALNUM
FIELDTYPE *TYPE_ALNUM;
/* ./fty_alpha.c */
typedef struct
{
int width;
}
alphaARG;
#undef TYPE_ALPHA
FIELDTYPE *TYPE_ALPHA;
/* ./fty_enum.c */
typedef struct
{
char **kwds;
int count;
NCURSES_BOOL checkcase;
NCURSES_BOOL checkunique;
}
enumARG;
#undef TYPE_ENUM
FIELDTYPE *TYPE_ENUM;
/* ./fty_int.c */
typedef struct
{
int precision;
long low;
long high;
}
integerARG;
#undef TYPE_INTEGER
FIELDTYPE *TYPE_INTEGER;
/* ./fty_ipv4.c */
#undef TYPE_IPV4
FIELDTYPE *TYPE_IPV4;
/* ./fty_num.c */
#include <locale.h>
typedef struct
{
int precision;
double low;
double high;
struct lconv *L;
}
numericARG;
#undef TYPE_NUMERIC
FIELDTYPE *TYPE_NUMERIC;
/* ./fty_regex.c */
#include <regex.h>
typedef struct
{
regex_t *pRegExp;
unsigned long *refCount;
}
RegExp_Arg;
#undef TYPE_REGEXP
FIELDTYPE *TYPE_REGEXP;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,67 @@
/****************************************************************************
* Copyright (c) 2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 2006 *
****************************************************************************/
/*
* $Id: hashed_db.h,v 1.5 2006/08/19 15:58:34 tom Exp $
*/
#ifndef HASHED_DB_H
#define HASHED_DB_H 1
#include <curses.h>
#if USE_HASHED_DB
#include <db.h>
#ifndef DBN_SUFFIX
#define DBM_SUFFIX ".db"
#endif
#ifdef DB_VERSION_MAJOR
#define HASHED_DB_API DB_VERSION_MAJOR
#else
#define HASHED_DB_API 1 /* e.g., db 1.8.5 */
#endif
extern NCURSES_EXPORT(DB *) _nc_db_open(const char * /* path */, bool /* modify */);
extern NCURSES_EXPORT(bool) _nc_db_have_data(DBT * /* key */, DBT * /* data */, char ** /* buffer */, int * /* size */);
extern NCURSES_EXPORT(bool) _nc_db_have_index(DBT * /* key */, DBT * /* data */, char ** /* buffer */, int * /* size */);
extern NCURSES_EXPORT(int) _nc_db_close(DB * /* db */);
extern NCURSES_EXPORT(int) _nc_db_first(DB * /* db */, DBT * /* key */, DBT * /* data */);
extern NCURSES_EXPORT(int) _nc_db_next(DB * /* db */, DBT * /* key */, DBT * /* data */);
extern NCURSES_EXPORT(int) _nc_db_get(DB * /* db */, DBT * /* key */, DBT * /* data */);
extern NCURSES_EXPORT(int) _nc_db_put(DB * /* db */, DBT * /* key */, DBT * /* data */);
#endif
#endif /* HASHED_DB_H */

View File

@ -0,0 +1,65 @@
/****************************************************************************
* Copyright (c) 2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 2006 *
****************************************************************************/
/* $Id: nc_tparm.h,v 1.4 2006/11/26 00:49:25 tom Exp $ */
/*
* Cast parameters past the formatting-string for tparm() to match the
* assumption of the varargs code.
*/
#define TPARM_ARG long
#define TPARM_N(n) (TPARM_ARG)(n)
#define TPARM_9(a,b,c,d,e,f,g,h,i,j) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f),TPARM_N(g),TPARM_N(h),TPARM_N(i),TPARM_N(j))
#if NCURSES_TPARM_VARARGS
#define TPARM_8(a,b,c,d,e,f,g,h,i) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f),TPARM_N(g),TPARM_N(h),TPARM_N(i))
#define TPARM_7(a,b,c,d,e,f,g,h) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f),TPARM_N(g),TPARM_N(h))
#define TPARM_6(a,b,c,d,e,f,g) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f),TPARM_N(g))
#define TPARM_5(a,b,c,d,e,f) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f))
#define TPARM_4(a,b,c,d,e) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e))
#define TPARM_3(a,b,c,d) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d))
#define TPARM_2(a,b,c) tparm(a,TPARM_N(b),TPARM_N(c))
#define TPARM_1(a,b) tparm(a,TPARM_N(b))
#define TPARM_0(a) tparm(a)
#else
#define TPARM_8(a,b,c,d,e,f,g,h,i) TPARM_9(a,b,c,d,e,f,g,h,i,0)
#define TPARM_7(a,b,c,d,e,f,g,h) TPARM_8(a,b,c,d,e,f,g,h,0)
#define TPARM_6(a,b,c,d,e,f,g) TPARM_7(a,b,c,d,e,f,g,0)
#define TPARM_5(a,b,c,d,e,f) TPARM_6(a,b,c,d,e,f,0)
#define TPARM_4(a,b,c,d,e) TPARM_5(a,b,c,d,e,0)
#define TPARM_3(a,b,c,d) TPARM_4(a,b,c,d,0)
#define TPARM_2(a,b,c) TPARM_3(a,b,c,0)
#define TPARM_1(a,b) TPARM_2(a,b,0)
#define TPARM_1(a,b) TPARM_2(a,b,0)
#define TPARM_0(a) TPARM_1(a,0)
#endif

View File

@ -0,0 +1,60 @@
.\"***************************************************************************
.\" Copyright (c) 2003-2004,2006 Free Software Foundation, Inc. *
.\" *
.\" Permission is hereby granted, free of charge, to any person obtaining a *
.\" copy of this software and associated documentation files (the *
.\" "Software"), to deal in the Software without restriction, including *
.\" without limitation the rights to use, copy, modify, merge, publish, *
.\" distribute, distribute with modifications, sublicense, and/or sell *
.\" copies of the Software, and to permit persons to whom the Software is *
.\" furnished to do so, subject to the following conditions: *
.\" *
.\" The above copyright notice and this permission notice shall be included *
.\" in all copies or substantial portions of the Software. *
.\" *
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
.\" *
.\" Except as contained in this notice, the name(s) of the above copyright *
.\" holders shall not be used in advertising or otherwise to promote the *
.\" sale, use or other dealings in this Software without prior written *
.\" authorization. *
.\"***************************************************************************
.\"
.\" Author: Thomas E. Dickey 2003
.\"
.\" $Id: key_defined.3x,v 1.4 2006/02/25 21:50:01 tom Exp $
.TH key_defined 3X ""
.SH NAME
\fBkey_defined\fP \- check if a keycode is defined
.SH SYNOPSIS
\fB#include <curses.h>\fP
.sp
\fBint key_defined(const char *definition);\fP
.SH DESCRIPTION
This is an extension to the curses library.
It permits an application to determine if a string is currently bound
to any keycode.
.SH RETURN VALUE
If the string is bound to a keycode, its value (greater than zero) is returned.
If no keycode is bound, zero is returned.
If the string conflicts with longer strings which are bound to keys, -1 is returned.
.SH PORTABILITY
These routines are specific to ncurses. They were not supported on
Version 7, BSD or System V implementations. It is recommended that
any code depending on them be conditioned using NCURSES_VERSION.
.SH SEE ALSO
\fBdefine_key\fR(3X).
.SH AUTHOR
Thomas Dickey.
.\"#
.\"# The following sets edit modes for GNU EMACS
.\"# Local Variables:
.\"# mode:nroff
.\"# fill-column:79
.\"# End:

View File

@ -0,0 +1,82 @@
.\"***************************************************************************
.\" Copyright (c) 2005,2006 Free Software Foundation, Inc. *
.\" *
.\" Permission is hereby granted, free of charge, to any person obtaining a *
.\" copy of this software and associated documentation files (the *
.\" "Software"), to deal in the Software without restriction, including *
.\" without limitation the rights to use, copy, modify, merge, publish, *
.\" distribute, distribute with modifications, sublicense, and/or sell *
.\" copies of the Software, and to permit persons to whom the Software is *
.\" furnished to do so, subject to the following conditions: *
.\" *
.\" The above copyright notice and this permission notice shall be included *
.\" in all copies or substantial portions of the Software. *
.\" *
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
.\" *
.\" Except as contained in this notice, the name(s) of the above copyright *
.\" holders shall not be used in advertising or otherwise to promote the *
.\" sale, use or other dealings in this Software without prior written *
.\" authorization. *
.\"***************************************************************************
.\"
.\" Author: Thomas E. Dickey
.\"
.\" $Id: legacy_coding.3x,v 1.2 2006/02/25 21:50:01 tom Exp $
.TH legacy_coding 3X ""
.SH NAME
\fBuse_legacy_coding\fR \- use terminal's default colors
.SH SYNOPSIS
\fB#include <curses.h>\fP
.sp
\fBint use_legacy_coding(int level);\fP
.SH DESCRIPTION
The
.I use_legacy_coding()
function is an extension to the curses library.
It allows the caller to change the result of \fBunctrl\fP,
and suppress related checks within the library that would normally
cause nonprinting characters to be rendered in visible form.
This affects only 8-bit characters.
.PP
The \fIlevel\fP parameter controls the result:
.RS
.TP 5
0
the library functions normally,
rendering nonprinting characters as described in \fBunctrl\fP(3X).
.TP
1
the library ignores \fBisprintf\fP for codes in the range 160-255.
.TP
2
the library ignores \fBisprintf\fP for codes in the range 128-255.
It also modifies the output of \fBunctrl\fP, showing codes in the
range 128-159 as is.
.RE
.SH RETURN VALUE
If the screen has not been initialized,
or the \fIlevel\fP parameter is out of range,
the function returns \fBERR\fP.
Otherwise, it returns the previous level: \fB0\fP, \fB1\fP or \fB2\fP.
.SH PORTABILITY
This routine is specific to ncurses.
It was not supported on Version 7, BSD or System V implementations.
It is recommended that any code depending on ncurses extensions
be conditioned using NCURSES_VERSION.
.SH SEE ALSO
\fBunctrl\fR.
.SH AUTHOR
Thomas Dickey (to support lynx's font-switching feature).
.\"#
.\"# The following sets edit modes for GNU EMACS
.\"# Local Variables:
.\"# mode:nroff
.\"# fill-column:79
.\"# End:

View File

@ -0,0 +1,547 @@
/****************************************************************************
* Copyright (c) 2002,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 2002,2005 *
****************************************************************************/
/* LINTLIBRARY */
/* ./m_attribs.c */
#include "menu.priv.h"
#undef set_menu_fore
int set_menu_fore(
MENU *menu,
chtype attr)
{ return(*(int *)0); }
#undef menu_fore
chtype menu_fore(
const MENU *menu)
{ return(*(chtype *)0); }
#undef set_menu_back
int set_menu_back(
MENU *menu,
chtype attr)
{ return(*(int *)0); }
#undef menu_back
chtype menu_back(
const MENU *menu)
{ return(*(chtype *)0); }
#undef set_menu_grey
int set_menu_grey(
MENU *menu,
chtype attr)
{ return(*(int *)0); }
#undef menu_grey
chtype menu_grey(
const MENU *menu)
{ return(*(chtype *)0); }
/* ./m_cursor.c */
#undef _nc_menu_cursor_pos
int _nc_menu_cursor_pos(
const MENU *menu,
const ITEM *item,
int *pY,
int *pX)
{ return(*(int *)0); }
#undef pos_menu_cursor
int pos_menu_cursor(
const MENU *menu)
{ return(*(int *)0); }
/* ./m_driver.c */
#undef _nc_Match_Next_Character_In_Item_Name
int _nc_Match_Next_Character_In_Item_Name(
MENU *menu,
int ch,
ITEM **item)
{ return(*(int *)0); }
#undef menu_driver
int menu_driver(
MENU *menu,
int c)
{ return(*(int *)0); }
/* ./m_format.c */
#undef set_menu_format
int set_menu_format(
MENU *menu,
int rows,
int cols)
{ return(*(int *)0); }
#undef menu_format
void menu_format(
const MENU *menu,
int *rows,
int *cols)
{ /* void */ }
/* ./m_global.c */
#undef _nc_Default_Menu
MENU _nc_Default_Menu;
#undef _nc_Default_Item
ITEM _nc_Default_Item;
#undef _nc_Connect_Items
NCURSES_BOOL _nc_Connect_Items(
MENU *menu,
ITEM **items)
{ return(*(NCURSES_BOOL *)0); }
#undef _nc_Disconnect_Items
void _nc_Disconnect_Items(
MENU *menu)
{ /* void */ }
#undef _nc_Calculate_Text_Width
int _nc_Calculate_Text_Width(
const TEXT *item)
{ return(*(int *)0); }
#undef _nc_Calculate_Item_Length_and_Width
void _nc_Calculate_Item_Length_and_Width(
MENU *menu)
{ /* void */ }
#undef _nc_Link_Items
void _nc_Link_Items(
MENU *menu)
{ /* void */ }
#undef _nc_Show_Menu
void _nc_Show_Menu(
const MENU *menu)
{ /* void */ }
#undef _nc_New_TopRow_and_CurrentItem
void _nc_New_TopRow_and_CurrentItem(
MENU *menu,
int new_toprow,
ITEM *new_current_item)
{ /* void */ }
/* ./m_hook.c */
#undef set_menu_init
int set_menu_init(
MENU *menu,
Menu_Hook func)
{ return(*(int *)0); }
#undef menu_init
Menu_Hook menu_init(
const MENU *menu)
{ return(*(Menu_Hook *)0); }
#undef set_menu_term
int set_menu_term(
MENU *menu,
Menu_Hook func)
{ return(*(int *)0); }
#undef menu_term
Menu_Hook menu_term(
const MENU *menu)
{ return(*(Menu_Hook *)0); }
#undef set_item_init
int set_item_init(
MENU *menu,
Menu_Hook func)
{ return(*(int *)0); }
#undef item_init
Menu_Hook item_init(
const MENU *menu)
{ return(*(Menu_Hook *)0); }
#undef set_item_term
int set_item_term(
MENU *menu,
Menu_Hook func)
{ return(*(int *)0); }
#undef item_term
Menu_Hook item_term(
const MENU *menu)
{ return(*(Menu_Hook *)0); }
/* ./m_item_cur.c */
#undef set_current_item
int set_current_item(
MENU *menu,
ITEM *item)
{ return(*(int *)0); }
#undef current_item
ITEM *current_item(
const MENU *menu)
{ return(*(ITEM **)0); }
#undef item_index
int item_index(
const ITEM *item)
{ return(*(int *)0); }
/* ./m_item_nam.c */
#undef item_name
const char *item_name(
const ITEM *item)
{ return(*(const char **)0); }
#undef item_description
const char *item_description(
const ITEM *item)
{ return(*(const char **)0); }
/* ./m_item_new.c */
#include <wctype.h>
#undef new_item
ITEM *new_item(
const char *name,
const char *description)
{ return(*(ITEM **)0); }
#undef free_item
int free_item(
ITEM *item)
{ return(*(int *)0); }
#undef set_menu_mark
int set_menu_mark(
MENU *menu,
const char *mark)
{ return(*(int *)0); }
#undef menu_mark
const char *menu_mark(
const MENU *menu)
{ return(*(const char **)0); }
/* ./m_item_opt.c */
#undef set_item_opts
int set_item_opts(
ITEM *item,
Item_Options opts)
{ return(*(int *)0); }
#undef item_opts_off
int item_opts_off(
ITEM *item,
Item_Options opts)
{ return(*(int *)0); }
#undef item_opts_on
int item_opts_on(
ITEM *item,
Item_Options opts)
{ return(*(int *)0); }
#undef item_opts
Item_Options item_opts(
const ITEM *item)
{ return(*(Item_Options *)0); }
/* ./m_item_top.c */
#undef set_top_row
int set_top_row(
MENU *menu,
int row)
{ return(*(int *)0); }
#undef top_row
int top_row(
const MENU *menu)
{ return(*(int *)0); }
/* ./m_item_use.c */
#undef set_item_userptr
int set_item_userptr(
ITEM *item,
void *userptr)
{ return(*(int *)0); }
#undef item_userptr
void *item_userptr(
const ITEM *item)
{ return(*(void **)0); }
/* ./m_item_val.c */
#undef set_item_value
int set_item_value(
ITEM *item,
NCURSES_BOOL value)
{ return(*(int *)0); }
#undef item_value
NCURSES_BOOL item_value(
const ITEM *item)
{ return(*(NCURSES_BOOL *)0); }
/* ./m_item_vis.c */
#undef item_visible
NCURSES_BOOL item_visible(
const ITEM *item)
{ return(*(NCURSES_BOOL *)0); }
/* ./m_items.c */
#undef set_menu_items
int set_menu_items(
MENU *menu,
ITEM **items)
{ return(*(int *)0); }
#undef menu_items
ITEM **menu_items(
const MENU *menu)
{ return(*(ITEM ***)0); }
#undef item_count
int item_count(
const MENU *menu)
{ return(*(int *)0); }
/* ./m_new.c */
#undef new_menu
MENU *new_menu(
ITEM **items)
{ return(*(MENU **)0); }
#undef free_menu
int free_menu(
MENU *menu)
{ return(*(int *)0); }
/* ./m_opts.c */
#undef set_menu_opts
int set_menu_opts(
MENU *menu,
Menu_Options opts)
{ return(*(int *)0); }
#undef menu_opts_off
int menu_opts_off(
MENU *menu,
Menu_Options opts)
{ return(*(int *)0); }
#undef menu_opts_on
int menu_opts_on(
MENU *menu,
Menu_Options opts)
{ return(*(int *)0); }
#undef menu_opts
Menu_Options menu_opts(
const MENU *menu)
{ return(*(Menu_Options *)0); }
/* ./m_pad.c */
#undef set_menu_pad
int set_menu_pad(
MENU *menu,
int pad)
{ return(*(int *)0); }
#undef menu_pad
int menu_pad(
const MENU *menu)
{ return(*(int *)0); }
/* ./m_pattern.c */
#undef menu_pattern
char *menu_pattern(
const MENU *menu)
{ return(*(char **)0); }
#undef set_menu_pattern
int set_menu_pattern(
MENU *menu,
const char *p)
{ return(*(int *)0); }
/* ./m_post.c */
#undef _nc_Post_Item
void _nc_Post_Item(
const MENU *menu,
const ITEM *item)
{ /* void */ }
#undef _nc_Draw_Menu
void _nc_Draw_Menu(
const MENU *menu)
{ /* void */ }
#undef post_menu
int post_menu(
MENU *menu)
{ return(*(int *)0); }
#undef unpost_menu
int unpost_menu(
MENU *menu)
{ return(*(int *)0); }
/* ./m_req_name.c */
#undef menu_request_name
const char *menu_request_name(
int request)
{ return(*(const char **)0); }
#undef menu_request_by_name
int menu_request_by_name(
const char *str)
{ return(*(int *)0); }
/* ./m_scale.c */
#undef scale_menu
int scale_menu(
const MENU *menu,
int *rows,
int *cols)
{ return(*(int *)0); }
/* ./m_spacing.c */
#undef set_menu_spacing
int set_menu_spacing(
MENU *menu,
int s_desc,
int s_row,
int s_col)
{ return(*(int *)0); }
#undef menu_spacing
int menu_spacing(
const MENU *menu,
int *s_desc,
int *s_row,
int *s_col)
{ return(*(int *)0); }
/* ./m_sub.c */
#undef set_menu_sub
int set_menu_sub(
MENU *menu,
WINDOW *win)
{ return(*(int *)0); }
#undef menu_sub
WINDOW *menu_sub(
const MENU *menu)
{ return(*(WINDOW **)0); }
/* ./m_trace.c */
#undef _nc_retrace_item
ITEM *_nc_retrace_item(
ITEM *code)
{ return(*(ITEM **)0); }
#undef _nc_retrace_item_ptr
ITEM **_nc_retrace_item_ptr(
ITEM **code)
{ return(*(ITEM ***)0); }
#undef _nc_retrace_item_opts
Item_Options _nc_retrace_item_opts(
Item_Options code)
{ return(*(Item_Options *)0); }
#undef _nc_retrace_menu
MENU *_nc_retrace_menu(
MENU *code)
{ return(*(MENU **)0); }
#undef _nc_retrace_menu_hook
Menu_Hook _nc_retrace_menu_hook(
Menu_Hook code)
{ return(*(Menu_Hook *)0); }
#undef _nc_retrace_menu_opts
Menu_Options _nc_retrace_menu_opts(
Menu_Options code)
{ return(*(Menu_Options *)0); }
/* ./m_userptr.c */
#undef set_menu_userptr
int set_menu_userptr(
MENU *menu,
void *userptr)
{ return(*(int *)0); }
#undef menu_userptr
void *menu_userptr(
const MENU *menu)
{ return(*(void **)0); }
/* ./m_win.c */
#undef set_menu_win
int set_menu_win(
MENU *menu,
WINDOW *win)
{ return(*(int *)0); }
#undef menu_win
WINDOW *menu_win(
const MENU *menu)
{ return(*(WINDOW **)0); }

View File

@ -0,0 +1,77 @@
/****************************************************************************
* Copyright (c) 2004,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey *
****************************************************************************/
#include "menu.priv.h"
MODULE_ID("$Id: m_trace.c,v 1.3 2005/01/16 01:06:11 tom Exp $")
NCURSES_EXPORT(ITEM *)
_nc_retrace_item(ITEM * code)
{
T((T_RETURN("%p"), code));
return code;
}
NCURSES_EXPORT(ITEM **)
_nc_retrace_item_ptr(ITEM ** code)
{
T((T_RETURN("%p"), code));
return code;
}
NCURSES_EXPORT(Item_Options)
_nc_retrace_item_opts(Item_Options code)
{
T((T_RETURN("%d"), code));
return code;
}
NCURSES_EXPORT(MENU *)
_nc_retrace_menu(MENU * code)
{
T((T_RETURN("%p"), code));
return code;
}
NCURSES_EXPORT(Menu_Hook)
_nc_retrace_menu_hook(Menu_Hook code)
{
T((T_RETURN("%p"), code));
return code;
}
NCURSES_EXPORT(Menu_Options)
_nc_retrace_menu_opts(Menu_Options code)
{
T((T_RETURN("%d"), code));
return code;
}

36
contrib/ncurses/misc/csort Executable file
View File

@ -0,0 +1,36 @@
#!/bin/sh
# $Id: csort,v 1.2 2002/10/19 21:42:09 tom Exp $
##############################################################################
# Copyright (c) 2002 Free Software Foundation, Inc. #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
# copy of this software and associated documentation files (the "Software"), #
# to deal in the Software without restriction, including without limitation #
# the rights to use, copy, modify, merge, publish, distribute, distribute #
# with modifications, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the #
# following conditions: #
# #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
# DEALINGS IN THE SOFTWARE. #
# #
# Except as contained in this notice, the name(s) of the above copyright #
# holders shall not be used in advertising or otherwise to promote the sale, #
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
#
# override anything that might cause 'sort' to do the wrong thing...
LANG=C; export LANG
LANGUAGE=C; export LANGUAGE
LC_ALL=C; export LC_ALL
LC_CTYPE=C; export LC_CTYPE
sort $*

View File

@ -0,0 +1,58 @@
#!/bin/sh
##############################################################################
# Copyright (c) 2004 Free Software Foundation, Inc. #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
# copy of this software and associated documentation files (the "Software"), #
# to deal in the Software without restriction, including without limitation #
# the rights to use, copy, modify, merge, publish, distribute, distribute #
# with modifications, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the #
# following conditions: #
# #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
# DEALINGS IN THE SOFTWARE. #
# #
# Except as contained in this notice, the name(s) of the above copyright #
# holders shall not be used in advertising or otherwise to promote the sale, #
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
#
# Author: Thomas E. Dickey
#
# $Id: gen_edit.sh,v 1.1 2004/07/11 15:01:29 tom Exp $
# Generate a sed-script for converting the terminfo.src to the form which will
# be installed.
#
# Assumes:
# The leaf directory names (lib, tabset, terminfo)
#
: ${ticdir=@TERMINFO@}
: ${xterm_new=@WHICH_XTERM@}
# If we're not installing into /usr/share/, we'll have to adjust the location
# of the tabset files in terminfo.src (which are in a parallel directory).
TABSET=`echo $ticdir | sed -e 's%/terminfo$%/tabset%'`
if test "x$TABSET" != "x/usr/share/tabset" ; then
cat <<EOF
s%/usr/share/tabset%$TABSET%g
EOF
fi
if test "$xterm_new" != "xterm-new" ; then
cat <<EOF
/^# This is xterm for ncurses/,/^$/{
s/use=xterm-new,/use=$WHICH_XTERM,/
}
EOF
fi

119
contrib/ncurses/misc/jpf-indent Executable file
View File

@ -0,0 +1,119 @@
#!/bin/sh
#****************************************************************************
#* Copyright (c) 2004-2005,2006 Thomas E. Dickey *
#* *
#* Permission is hereby granted, free of charge, to any person obtaining a *
#* copy of this software and associated documentation files (the *
#* "Software"), to deal in the Software without restriction, including *
#* without limitation the rights to use, copy, modify, merge, publish, *
#* distribute, distribute with modifications, sublicense, and/or sell *
#* copies of the Software, and to permit persons to whom the Software is *
#* furnished to do so, subject to the following conditions: *
#* *
#* The above copyright notice and this permission notice shall be included *
#* in all copies or substantial portions of the Software. *
#* *
#* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
#* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
#* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
#* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
#* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
#* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
#* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
#* *
#* Except as contained in this notice, the name(s) of the above copyright *
#* holders shall not be used in advertising or otherwise to promote the *
#* sale, use or other dealings in this Software without prior written *
#* authorization. *
#****************************************************************************/
# $Id: jpf-indent,v 1.6 2006/02/18 17:07:15 tom Exp $
# indent ncurses source written by Juergen Pfeifer
NOOP=no
OPTS='
-npro
--blank-lines-after-declarations
--blank-lines-after-procedures
--brace-indent2
--braces-after-if-line
--continue-at-parentheses
--indent-level2
--line-length80
--no-space-after-casts
--no-space-after-function-call-names
--parameter-indentation4
--swallow-optional-blank-lines
--tab-size8
-T FIELD
-T FIELDTYPE
-T FIELD_CELL
-T FORM
-T NCURSES_INLINE
-T RegExp_Arg
-T TypeArgument
-T WINDOW
-T attr_t
-T bool
-T cchar_t
-T chtype
-T enumARG
-T va_list
-T wchar_t
'
for name in $*
do
case $name in
-v|-n)
NOOP=yes
OPTS="$OPTS -v"
;;
-*)
OPTS="$OPTS $name"
;;
*.[ch])
save="${name}".a$$
test="${name}".b$$
rm -f "$save" "$test"
mv "$name" "$save"
sed \
-e '/MODULE_ID(/s/)$/);/' \
-e 's,\<GCC_NORETURN;,;//GCC_NORETURN;,' \
-e 's,\<GCC_PRINTFLIKE(,;//GCC_PRINTFLIKE(,' \
-e 's,\<GCC_SCANFLIKE(,;//GCC_SCANFLIKE(,' \
-e 's,\(\<NCURSES_EXPORT_VAR\>\),//\1,' \
"$save" >"$test"
cp "$test" "$name"
chmod u+w "$name"
# ${INDENT_PROG-indent} --version
${INDENT_PROG-indent} -npro $OPTS "$name"
sed \
-e '/MODULE_ID(/s/);$/)/' \
-e 's,;[ ]*//GCC_NORETURN;, GCC_NORETURN;,' \
-e 's,;[ ]*//GCC_PRINTFLIKE(, GCC_PRINTFLIKE(,' \
-e 's,;[ ]*//GCC_SCANFLIKE(, GCC_SCANFLIKE(,' \
-e 's,//\(\<NCURSES_EXPORT_VAR\>\),\1,' \
"$name" >"$test"
mv "$test" "$name"
rm -f "${name}~"
if test $NOOP = yes ; then
if (cmp -s "$name" "$save" ) then
echo "** no change: $name"
else
diff -u "$save" "$name"
fi
rm -f "$name"
mv "$save" "$name"
elif ( cmp -s "$name" "$save" ) ; then
echo "** unchanged $name"
rm -f "${name}"
mv "$save" "$name"
else
echo "** updated $name"
rm -f "$save"
fi
;;
*)
echo "** ignored: $name"
;;
esac
done

130
contrib/ncurses/misc/ncu-indent Executable file
View File

@ -0,0 +1,130 @@
#!/bin/sh
#****************************************************************************
#* Copyright (c) 2001-2005,2006 Thomas E. Dickey *
#* *
#* Permission is hereby granted, free of charge, to any person obtaining a *
#* copy of this software and associated documentation files (the *
#* "Software"), to deal in the Software without restriction, including *
#* without limitation the rights to use, copy, modify, merge, publish, *
#* distribute, distribute with modifications, sublicense, and/or sell *
#* copies of the Software, and to permit persons to whom the Software is *
#* furnished to do so, subject to the following conditions: *
#* *
#* The above copyright notice and this permission notice shall be included *
#* in all copies or substantial portions of the Software. *
#* *
#* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
#* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
#* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
#* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
#* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
#* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
#* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
#* *
#* Except as contained in this notice, the name(s) of the above copyright *
#* holders shall not be used in advertising or otherwise to promote the *
#* sale, use or other dealings in this Software without prior written *
#* authorization. *
#****************************************************************************/
# $Id: ncu-indent,v 1.16 2006/02/18 17:02:22 tom Exp $
NOOP=no
OPTS='
--blank-lines-after-procedures
--braces-on-if-line
--continuation-indentation0
--continue-at-parentheses
--cuddle-else
--indent-level4
--leave-preprocessor-space
--no-blank-lines-after-commas
--no-blank-lines-after-declarations
--no-space-after-function-call-names
--procnames-start-lines
--space-special-semicolon
--swallow-optional-blank-lines
--tab-size8
-T NCURSES_EXPORT_VAR
-T NCURSES_INLINE
-T SCREEN
-T TERMTYPE
-T attr_t
-T cchar_t
-T chtype
-T inline
-T wchar_t
-T wint_t
-T BUFFER
-T CHARTYPE
-T FILE
-T GCC_NORETURN
-T LINE
-T MARK
-T RETSIGTYPE
-T TBUFF
-T WINDOW
-T size_t
-T va_list
-T Cardinal
-T Widget
-T XtPointer
'
for name in $*
do
case $name in
-v|-n)
NOOP=yes
OPTS="$OPTS -v"
;;
-*)
OPTS="$OPTS $name"
;;
*.[ch]|*.cc|*.cpp)
save="${name}".a$$
test="${name}".b$$
rm -f "$save" "$test"
mv "$name" "$save"
sed \
-e '/MODULE_ID(/s/)$/);/' \
-e 's,\<GCC_NORETURN;,;//GCC_NORETURN;,' \
-e 's,\<GCC_PRINTFLIKE(,;//GCC_PRINTFLIKE(,' \
-e 's,\<GCC_SCANFLIKE(,;//GCC_SCANFLIKE(,' \
-e 's,\(\<NCURSES_EXPORT_VAR\>\),//\1,' \
"$save" >"$test"
cp "$test" "$name"
chmod u+w "$name"
# ${INDENT_PROG-indent} --version
${INDENT_PROG-indent} -npro $OPTS "$name"
sed \
-e '/MODULE_ID(/s/);$/)/' \
-e 's,;[ ]*//GCC_NORETURN;, GCC_NORETURN;,' \
-e 's,;[ ]*//GCC_PRINTFLIKE(, GCC_PRINTFLIKE(,' \
-e 's,;[ ]*//GCC_SCANFLIKE(, GCC_SCANFLIKE(,' \
-e 's,//\(\<NCURSES_EXPORT_VAR\>\),\1,' \
"$name" >"$test"
mv "$test" "$name"
rm -f "${name}~"
if test $NOOP = yes ; then
if (cmp -s "$name" "$save" ) then
echo "** no change: $name"
else
diff -u "$save" "$name"
fi
rm -f "$name"
mv "$save" "$name"
elif ( cmp -s "$name" "$save" ) ; then
echo "** unchanged $name"
rm -f "${name}"
mv "$save" "$name"
else
echo "** updated $name"
rm -f "$save"
fi
;;
*)
echo "** ignored: $name"
;;
esac
done

View File

@ -0,0 +1,156 @@
#!@SHELL@
# $Id: ncurses-config.in,v 1.11 2006/10/28 20:22:52 tom Exp $
##############################################################################
# Copyright (c) 2006 Free Software Foundation, Inc. #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
# copy of this software and associated documentation files (the "Software"), #
# to deal in the Software without restriction, including without limitation #
# the rights to use, copy, modify, merge, publish, distribute, distribute #
# with modifications, sublicense, and/or sell copies of the Software, and to #
# permit persons to whom the Software is furnished to do so, subject to the #
# following conditions: #
# #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
# DEALINGS IN THE SOFTWARE. #
# #
# Except as contained in this notice, the name(s) of the above copyright #
# holders shall not be used in advertising or otherwise to promote the sale, #
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
#
# Author: Thomas E. Dickey, 2006
prefix="@prefix@"
exec_prefix="@exec_prefix@"
bindir="@bindir@"
libdir="@libdir@"
datadir="@datadir@"
mandir="@mandir@"
THIS="ncurses@DFT_ARG_SUFFIX@"
test $# = 0 && exec @SHELL@ $0 --error
while test $# -gt 0; do
case "$1" in
-*=*)
ARG=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
;;
*)
ARG=
;;
esac
case "$1" in
# basic configuration
--prefix=*)
prefix="$ARG"
test -z "$exec_prefix" && exec_prefix="$ARG"
;;
--prefix)
echo "$prefix"
;;
--exec-prefix=*)
exec_prefix="$ARG"
;;
--exec-prefix)
echo "$exec_prefix"
;;
# compile/link
--cflags)
INCS=
if test "${prefix}/include" != /usr/include ; then
INCS="-I${prefix}/include"
fi
if test "@WITH_OVERWRITE@" != no ; then
INCS="$INCS -I${prefix}/include/${THIS}"
fi
sed -e 's,^[ ]*,,' -e 's, [ ]*, ,g' -e 's,[ ]*$,,' <<-ENDECHO
$INCS
ENDECHO
;;
--libs)
sed -e 's,^[ ]*,,' -e 's, [ ]*, ,g' -e 's,[ ]*$,,' <<-ENDECHO
-L${exec_prefix}/lib @EXTRA_LDFLAGS@ -l${THIS} @LIBS@
ENDECHO
;;
# identification
--version)
echo "@NCURSES_MAJOR@.@NCURSES_MINOR@.@NCURSES_PATCH@"
;;
--abi-version)
echo "@cf_cv_abi_version@"
;;
--mouse-version)
echo "@NCURSES_MOUSE_VERSION@"
;;
# locations
--bindir)
echo "${bindir}"
;;
--datadir)
echo "${datadir}"
;;
--libdir)
echo "${libdir}"
;;
--mandir)
echo "${mandir}"
;;
--terminfo)
echo "@TERMINFO@"
;;
--terminfo-dirs)
echo "@TERMINFO_DIRS@"
;;
--termpath)
echo "@TERMPATH@"
;;
# general info
--help)
cat <<ENDHELP
Usage: ${THIS}-config [options]
Options:
--prefix echos the package-prefix of ${THIS}
--prefix=ARG sets the package-prefix of ${THIS}
--exec-prefix echos the executable-prefix of ${THIS}
--exec-prefix=ARG sets the executable-prefix of ${THIS}
--cflags echos the C compiler flags needed to compile with ${THIS}
--libs echos the libraries needed to link with ${THIS}
--version echos the release+patchdate version of ${THIS}
--abi-version echos the ABI version of ${THIS}
--mouse-version echos the mouse-interface version of ${THIS}
--bindir echos the directory containing ${THIS} programs
--datadir echos the directory containing ${THIS} data
--libdir echos the directory containing ${THIS} libraries
--mandir echos the directory containing ${THIS} manpages
--terminfo echos the \$TERMINFO terminfo database path
--terminfo-dirs echos the \$TERMINFO_DIRS directory list
--termpath echos the \$TERMPATH termcap list
--help prints this message
ENDHELP
;;
--error|*)
@SHELL@ $0 --help 1>&2
exit 1
;;
esac
shift
done
# vile:shmode

View File

@ -0,0 +1,95 @@
-------------------------------------------------------------------------------
-- Copyright (c) 2002,2006 Free Software Foundation, Inc. --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files (the --
-- "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, distribute with modifications, sublicense, and/or sell copies --
-- of the Software, and to permit persons to whom the Software is furnished --
-- to do so, subject to the following conditions: --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN --
-- NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE --
-- USE OR OTHER DEALINGS IN THE SOFTWARE. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
-------------------------------------------------------------------------------
-- $Id: README.IZ,v 1.2 2006/04/22 23:13:05 tom Exp $
---------------------------------------------------------------------
Here is the patch. I did no testing whatsoever with event watching
requests present (I need some applications which exersize this before
this, probably lynx ;-), but the code looks working "the normal way".
I had no way to test that the poll() branch compiles/works...
Here is the API:
*) two new functions wgetch_events() wgetstrn_event() are introduced,
which allow an event-watch specification given as the last argument;
*) if the last argument is NULL, they behave as wgetch() and
wgetstrn() (TESTED!);
*) the event specification is a pointer to _nc_eventlist, which
contains bookkeeping elements (count and the summary of results),
and an array of pointers to _nc_event;
*) each _nc_event is a typed union, with two types supported "as
shipped": _NC_EVENT_TIMEOUT_MSEC, _NC_EVENT_FILE. For
_NC_EVENT_FILE the fields are fd, flag, and the output field.
*) The only supported flag "as shipped" is _NC_EVENT_FILE_READABLE.
If the file was found readable, the return field is set to this,
otherwise to 0;
*) If these functions return KEY_EVENT, this means that the return
fields in both the _nc_eventlist and _nc_event structures make
sense. The field result_flags of _nc_eventlist may have a
combination of bits _NC_EVENT_TIMEOUT_MSEC and _NC_EVENT_FILE_READABLE
set;
*) The timeout_msec field of _NC_EVENT_TIMEOUT_MSEC _nc_event's is
updated on return, even if the return is not KEY_EVENT. However,
the change in the value represents only the amount of time spent in
waiting for events, not the amount of time spent bookkeeping;
*) the return KEY_EVENT of wgetstrn_event() means that the output
string includes the user input typed so far, but the user did not have
a chance to press ENTER (or whatever). This call should be
repeated (with "shifted" pointer to a buffer, of course) to
complete the input;
*) The presence of this extension can be checked via inspecting
#ifdef NCURSES_EVENT_VERSION. This symbol is not defined on BeOS,
since there is no support for this on BeOS.
Known issues: calls interrupted by KEY_EVENT reset the ESCDELAY
timer. This is not entirely new, since other synthetic events behave
the same (see "if (ch >= KEY_MIN)" branch of kgetch()). However,
KEY_EVENT may be generated in a continuous stream (say, when
downloading a file), thus this may be more important than with other
synthetic keys. An additional field in window structure which keeps
timestamp of the first raw key in the queue may be needed to
circumvent this.
Another possible issue: KEY_EVENT has a preference over a user input,
so a stream of KEY_EVENT's can make input hard. Maybe use
result_flags as in input parameter too, which specifies whether the
user input should have higher precedence?
Also: I took an opportunity to document kgetch() better.
Enjoy,
Ilya

View File

@ -0,0 +1,76 @@
/****************************************************************************
* Copyright (c) 2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey, 2003 *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: key_defined.c,v 1.3 2003/05/17 23:12:27 tom Exp $")
static int
find_definition(struct tries *tree, const char *str)
{
struct tries *ptr;
int result = 0;
if (str != 0 && *str != '\0') {
for (ptr = tree; ptr != 0; ptr = ptr->sibling) {
if (UChar(*str) == UChar(ptr->ch)) {
if (str[1] == '\0' && ptr->child != 0) {
result = -1;
} else if ((result = find_definition(ptr->child, str + 1)) == 0) {
result = ptr->value;
} else if (str[1] == '\0') {
result = -1;
}
}
if (result != 0)
break;
}
}
return (result);
}
/*
* Returns the keycode associated with the given string. If none is found,
* return 0. If the string is only a prefix to other strings, return -1.
*/
NCURSES_EXPORT(int)
key_defined(const char *str)
{
int code = ERR;
T((T_CALLED("key_defined(%s)"), _nc_visbuf(str)));
if (SP != 0 && str != 0) {
code = find_definition(SP->_keytry, str);
}
returnCode(code);
}

View File

@ -0,0 +1,48 @@
/****************************************************************************
* Copyright (c) 2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: legacy_coding.c,v 1.2 2005/12/17 23:38:17 tom Exp $")
NCURSES_EXPORT(int)
use_legacy_coding(int level)
{
int result = ERR;
T((T_CALLED("use_legacy_coding(%d)"), level));
if (level >= 0 && level <= 2 && SP != 0) {
result = SP->_legacy_coding;
SP->_legacy_coding = level;
}
returnCode(result);
}

View File

@ -0,0 +1,68 @@
/****************************************************************************
* Copyright (c) 2004 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey *
****************************************************************************/
/*
** lib_insnstr.c
**
** The routine winsnstr().
**
*/
#include <curses.priv.h>
#include <ctype.h>
MODULE_ID("$Id: lib_insnstr.c,v 1.1 2004/02/28 23:44:56 tom Exp $")
NCURSES_EXPORT(int)
winsnstr(WINDOW *win, const char *s, int n)
{
int code = ERR;
NCURSES_SIZE_T oy;
NCURSES_SIZE_T ox;
const unsigned char *str = (const unsigned char *) s;
const unsigned char *cp;
T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbufn(s, n), n));
if (win != 0 && str != 0) {
oy = win->_cury;
ox = win->_curx;
for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
_nc_insert_ch(win, (chtype) UChar(*cp));
}
win->_curx = ox;
win->_cury = oy;
_nc_synchook(win);
code = OK;
}
returnCode(code);
}

View File

@ -0,0 +1,227 @@
/****************************************************************************
* Copyright (c) 2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 2006 *
****************************************************************************/
/*
* Iterators for terminal databases.
*/
#include <curses.priv.h>
#include <tic.h>
MODULE_ID("$Id: db_iterator.c,v 1.5 2006/12/16 19:06:42 tom Exp $")
static bool have_tic_directory = FALSE;
static bool keep_tic_directory = FALSE;
/*
* Record the "official" location of the terminfo directory, according to
* the place where we're writing to, or the normal default, if not.
*/
NCURSES_EXPORT(const char *)
_nc_tic_dir(const char *path)
{
static const char *result = TERMINFO;
if (!keep_tic_directory) {
if (path != 0) {
result = path;
have_tic_directory = TRUE;
} else if (!have_tic_directory && use_terminfo_vars()) {
char *envp;
if ((envp = getenv("TERMINFO")) != 0)
return _nc_tic_dir(envp);
}
}
return result;
}
/*
* Special fix to prevent the terminfo directory from being moved after tic
* has chdir'd to it. If we let it be changed, then if $TERMINFO has a
* relative path, we'll lose track of the actual directory.
*/
NCURSES_EXPORT(void)
_nc_keep_tic_dir(const char *path)
{
_nc_tic_dir(path);
keep_tic_directory = TRUE;
}
/*
* Process the list of :-separated directories, looking for the terminal type.
* We don't use strtok because it does not show us empty tokens.
*/
static char *this_db_list = 0;
static int size_db_list;
/*
* Cleanup.
*/
NCURSES_EXPORT(void)
_nc_last_db(void)
{
if (this_db_list != 0) {
FreeAndNull(this_db_list);
}
size_db_list = 0;
}
/* The TERMINFO_DIRS value, if defined by the configure script, begins with a
* ":", which will be interpreted as TERMINFO.
*/
static const char *
next_list_item(const char *source, int *offset)
{
if (source != 0) {
FreeIfNeeded(this_db_list);
this_db_list = strdup(source);
size_db_list = strlen(source);
}
if (this_db_list != 0 && size_db_list && *offset < size_db_list) {
static char system_db[] = TERMINFO;
char *result = this_db_list + *offset;
char *marker = strchr(result, NCURSES_PATHSEP);
/*
* Put a null on the marker if a separator was found. Set the offset
* to the next position after the marker so we can call this function
* again, using the data at the offset.
*/
if (marker == 0) {
*offset += strlen(result) + 1;
marker = result + *offset;
} else {
*marker++ = 0;
*offset = marker - this_db_list;
}
if (*result == 0 && result != (this_db_list + size_db_list))
result = system_db;
return result;
}
return 0;
}
#define NEXT_DBD(var, offset) next_list_item((*offset == 0) ? var : 0, offset)
/*
* This is a simple iterator which allows the caller to step through the
* possible locations for a terminfo directory. ncurses uses this to find
* terminfo files to read.
*/
NCURSES_EXPORT(const char *)
_nc_next_db(DBDIRS * state, int *offset)
{
const char *result;
char *envp;
while (*state < dbdLAST) {
DBDIRS next = (DBDIRS) ((int) (*state) + 1);
result = 0;
switch (*state) {
case dbdTIC:
if (have_tic_directory)
result = _nc_tic_dir(0);
break;
#if USE_DATABASE
case dbdEnvOnce:
if (use_terminfo_vars()) {
if ((envp = getenv("TERMINFO")) != 0)
result = _nc_tic_dir(envp);
}
break;
case dbdHome:
if (use_terminfo_vars()) {
result = _nc_home_terminfo();
}
break;
case dbdEnvList:
if (use_terminfo_vars()) {
if ((result = NEXT_DBD(getenv("TERMINFO_DIRS"), offset)) != 0)
next = *state;
}
break;
case dbdCfgList:
#ifdef TERMINFO_DIRS
if ((result = NEXT_DBD(TERMINFO_DIRS, offset)) != 0)
next = *state;
#endif
break;
case dbdCfgOnce:
#ifndef TERMINFO_DIRS
result = TERMINFO;
#endif
break;
#endif /* USE_DATABASE */
#if USE_TERMCAP
case dbdEnvOnce2:
if (use_terminfo_vars()) {
if ((envp = getenv("TERMCAP")) != 0)
result = _nc_tic_dir(envp);
}
break;
case dbdEnvList2:
if (use_terminfo_vars()) {
if ((result = NEXT_DBD(getenv("TERMPATH"), offset)) != 0)
next = *state;
}
break;
case dbdCfgList2:
if ((result = NEXT_DBD(TERMPATH, offset)) != 0)
next = *state;
break;
#endif /* USE_TERMCAP */
case dbdLAST:
break;
}
if (*state != next) {
*state = next;
*offset = 0;
_nc_last_db();
}
if (result != 0) {
return result;
}
}
return 0;
}
NCURSES_EXPORT(void)
_nc_first_db(DBDIRS * state, int *offset)
{
*state = dbdTIC;
*offset = 0;
}

View File

@ -0,0 +1,260 @@
/****************************************************************************
* Copyright (c) 2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 2006 *
****************************************************************************/
#include <curses.priv.h>
#include <tic.h>
#include <hashed_db.h>
#if USE_HASHED_DB
MODULE_ID("$Id: hashed_db.c,v 1.13 2006/08/19 19:48:38 tom Exp $")
#if HASHED_DB_API >= 2
static DBC *cursor;
#endif
/*
* Open the database.
*/
NCURSES_EXPORT(DB *)
_nc_db_open(const char *path, bool modify)
{
DB *result = 0;
#if HASHED_DB_API >= 4
db_create(&result, NULL, 0);
result->open(result,
NULL,
path,
NULL,
DB_HASH,
modify ? DB_CREATE : DB_RDONLY,
0644);
#elif HASHED_DB_API >= 3
db_create(&result, NULL, 0);
result->open(result,
path,
NULL,
DB_HASH,
modify ? DB_CREATE : DB_RDONLY,
0644);
#elif HASHED_DB_API >= 2
int code;
if ((code = db_open(path,
DB_HASH,
modify ? DB_CREATE : DB_RDONLY,
0644,
(DB_ENV *) 0,
(DB_INFO *) 0,
&result)) != 0) {
T(("cannot open %s: %s", path, strerror(code)));
result = 0;
} else {
T(("opened %s", path));
}
#else
result = dbopen(path,
modify ? (O_CREAT | O_RDWR) : O_RDONLY,
0644,
DB_HASH,
NULL);
if (result != 0) {
T(("opened %s", path));
}
#endif
return result;
}
/*
* Close the database. Do not attempt to use the 'db' handle after this call.
*/
NCURSES_EXPORT(int)
_nc_db_close(DB * db)
{
int result;
#if HASHED_DB_API >= 2
result = db->close(db, 0);
#else
result = db->close(db);
#endif
return result;
}
/*
* Write a record to the database.
*
* Returns 0 on success.
*
* FIXME: the FreeBSD cap_mkdb program assumes the database could have
* duplicates. There appears to be no good reason for that (review/fix).
*/
NCURSES_EXPORT(int)
_nc_db_put(DB * db, DBT * key, DBT * data)
{
int result;
#if HASHED_DB_API >= 2
/* remove any pre-existing value, since we do not want duplicates */
(void) db->del(db, NULL, key, 0);
result = db->put(db, NULL, key, data, DB_NOOVERWRITE);
#else
result = db->put(db, key, data, R_NOOVERWRITE);
#endif
return result;
}
/*
* Read a record from the database.
*
* Returns 0 on success.
*/
NCURSES_EXPORT(int)
_nc_db_get(DB * db, DBT * key, DBT * data)
{
int result;
memset(data, 0, sizeof(*data));
#if HASHED_DB_API >= 2
result = db->get(db, NULL, key, data, 0);
#else
result = db->get(db, key, data, 0);
#endif
return result;
}
/*
* Read the first record from the database, ignoring order.
*
* Returns 0 on success.
*/
NCURSES_EXPORT(int)
_nc_db_first(DB * db, DBT * key, DBT * data)
{
int result;
memset(key, 0, sizeof(*key));
memset(data, 0, sizeof(*data));
#if HASHED_DB_API >= 2
if ((result = db->cursor(db, NULL, &cursor, 0)) == 0) {
result = cursor->c_get(cursor, key, data, DB_FIRST);
}
#else
result = db->seq(db, key, data, 0);
#endif
return result;
}
/*
* Read the next record from the database, ignoring order.
*
* Returns 0 on success.
*/
NCURSES_EXPORT(int)
_nc_db_next(DB * db, DBT * key, DBT * data)
{
int result;
#if HASHED_DB_API >= 2
(void) db;
if (cursor != 0) {
result = cursor->c_get(cursor, key, data, DB_NEXT);
} else {
result = -1;
}
#else
result = db->seq(db, key, data, 0);
#endif
return result;
}
/*
* Check if a record is a terminfo index record. Index records are those that
* contain only an alias pointing to a list of aliases.
*/
NCURSES_EXPORT(bool)
_nc_db_have_index(DBT * key, DBT * data, char **buffer, int *size)
{
bool result = FALSE;
int used = data->size - 1;
char *have = (char *) data->data;
(void) key;
if (*have++ == 2) {
result = TRUE;
}
/*
* Update params in any case for consistency with _nc_db_have_data().
*/
*buffer = have;
*size = used;
return result;
}
/*
* Check if a record is the terminfo data record. Ignore index records, e.g.,
* those that contain only an alias pointing to a list of aliases.
*/
NCURSES_EXPORT(bool)
_nc_db_have_data(DBT * key, DBT * data, char **buffer, int *size)
{
bool result = FALSE;
int used = data->size - 1;
char *have = (char *) data->data;
if (*have++ == 0) {
if (data->size > key->size
&& IS_TIC_MAGIC(have)) {
result = TRUE;
}
}
/*
* Update params in any case to make it simple to follow a index record
* to the data record.
*/
*buffer = have;
*size = used;
return result;
}
#else
extern
NCURSES_EXPORT(void)
_nc_hashed_db(void);
NCURSES_EXPORT(void)
_nc_hashed_db(void)
{
}
#endif /* USE_HASHED_DB */

View File

@ -0,0 +1,328 @@
/****************************************************************************
* Copyright (c) 2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas Dickey *
****************************************************************************/
#include <curses.priv.h>
#include <ctype.h>
#include <tic.h>
#include <term_entry.h>
MODULE_ID("$Id: trim_sgr0.c,v 1.7 2006/12/02 19:37:57 tom Exp $")
#undef CUR
#define CUR tp->
#define CSI 233
#define ESC 033 /* ^[ */
#define L_BRACK '['
static char *
set_attribute_9(TERMTYPE *tp, int flag)
{
const char *result;
if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0)
result = "";
return strdup(result);
}
static int
is_csi(const char *s)
{
if (UChar(s[0]) == CSI)
return 1;
else if (s[0] == ESC && s[1] == L_BRACK)
return 2;
return 0;
}
static char *
skip_zero(char *s)
{
if (s[0] == '0') {
if (s[1] == ';')
s += 2;
else if (isalpha(UChar(s[1])))
s += 1;
}
return s;
}
static const char *
skip_delay(const char *s)
{
if (s[0] == '$' && s[1] == '<') {
s += 2;
while (isdigit(UChar(*s)) || *s == '/')
++s;
if (*s == '>')
++s;
}
return s;
}
/*
* Improve similar_sgr a little by moving the attr-string from the beginning
* to the end of the s-string.
*/
static bool
rewrite_sgr(char *s, char *attr)
{
if (PRESENT(s)) {
if (PRESENT(attr)) {
unsigned len_s = strlen(s);
unsigned len_a = strlen(attr);
if (len_s > len_a && !strncmp(attr, s, len_a)) {
unsigned n;
TR(TRACE_DATABASE, ("rewrite:\n\t%s", s));
for (n = 0; n < len_s - len_a; ++n) {
s[n] = s[n + len_a];
}
strcpy(s + n, attr);
TR(TRACE_DATABASE, ("to:\n\t%s", s));
}
}
return TRUE;
}
return FALSE; /* oops */
}
static bool
similar_sgr(char *a, char *b)
{
bool result = FALSE;
int csi_a = is_csi(a);
int csi_b = is_csi(b);
unsigned len_a;
unsigned len_b;
TR(TRACE_DATABASE, ("similar_sgr:\n\t%s\n\t%s",
_nc_visbuf2(1, a),
_nc_visbuf2(2, b)));
if (csi_a != 0 && csi_b != 0 && csi_a == csi_b) {
a += csi_a;
b += csi_b;
if (*a != *b) {
a = skip_zero(a);
b = skip_zero(b);
}
}
len_a = strlen(a);
len_b = strlen(b);
if (len_a && len_b) {
if (len_a > len_b)
result = (strncmp(a, b, len_b) == 0);
else
result = (strncmp(a, b, len_a) == 0);
}
TR(TRACE_DATABASE, ("...similar_sgr: %d\n\t%s\n\t%s", result,
_nc_visbuf2(1, a),
_nc_visbuf2(2, b)));
return result;
}
static unsigned
chop_out(char *string, unsigned i, unsigned j)
{
TR(TRACE_DATABASE, ("chop_out %d..%d from %s", i, j, _nc_visbuf(string)));
while (string[j] != '\0') {
string[i++] = string[j++];
}
string[i] = '\0';
return i;
}
/*
* Compare, ignoring delays. Some of the delay values are inconsistent, and
* we do not want to be stopped by that.
*
* Returns the number of chars from 'full' that we matched. If any mismatch
* occurs, return zero.
*/
static int
compare_part(const char *part, const char *full)
{
const char *next_part;
const char *next_full;
int used_full = 0;
int used_delay = 0;
while (*part != 0) {
if (*part != *full) {
used_full = 0;
break;
}
/*
* Adjust the return-value to allow the rare case of
* string<delay>string
* to remove the whole piece. The most common case is a delay at the
* end of the string. The adjusted string will retain the delay, which
* is conservative.
*/
if (used_delay != 0) {
used_full += used_delay;
used_delay = 0;
}
if (*part == '$' && *full == '$') {
next_part = skip_delay(part);
next_full = skip_delay(full);
if (next_part != part && next_full != full) {
used_delay += (next_full - full);
full = next_full;
part = next_part;
continue;
}
}
++used_full;
++part;
++full;
}
return used_full;
}
/*
* While 'sgr0' is the "same" as termcap 'me', there is a compatibility issue.
* The sgr/sgr0 capabilities include setting/clearing alternate character set
* mode. A termcap application cannot use sgr, so sgr0 strings that reset
* alternate character set mode will be misinterpreted. Here, we remove those
* from the more common ISO/ANSI/VT100 entries, which have sgr0 agreeing with
* sgr.
*
* This function returns the modified sgr0 if it can be modified, a null if
* an error occurs, or the original sgr0 if no change is needed.
*/
NCURSES_EXPORT(char *)
_nc_trim_sgr0(TERMTYPE *tp)
{
char *result = exit_attribute_mode;
T((T_CALLED("_nc_trim_sgr0()")));
if (PRESENT(exit_attribute_mode)
&& PRESENT(set_attributes)) {
bool found = FALSE;
char *on = set_attribute_9(tp, 1);
char *off = set_attribute_9(tp, 0);
char *end = strdup(exit_attribute_mode);
char *tmp;
size_t i, j, k;
TR(TRACE_DATABASE, ("checking if we can trim sgr0 based on sgr"));
TR(TRACE_DATABASE, ("sgr0 %s", _nc_visbuf(end)));
TR(TRACE_DATABASE, ("sgr(9:off) %s", _nc_visbuf(off)));
TR(TRACE_DATABASE, ("sgr(9:on) %s", _nc_visbuf(on)));
if (!rewrite_sgr(on, enter_alt_charset_mode)
|| !rewrite_sgr(off, exit_alt_charset_mode)
|| !rewrite_sgr(end, exit_alt_charset_mode)) {
FreeIfNeeded(on);
FreeIfNeeded(off);
FreeIfNeeded(end);
} else if (similar_sgr(off, end)
&& !similar_sgr(off, on)) {
TR(TRACE_DATABASE, ("adjusting sgr(9:off) : %s", _nc_visbuf(off)));
result = off;
/*
* If rmacs is a substring of sgr(0), remove that chunk.
*/
if (exit_alt_charset_mode != 0) {
TR(TRACE_DATABASE, ("scan for rmacs %s", _nc_visbuf(exit_alt_charset_mode)));
j = strlen(off);
k = strlen(exit_alt_charset_mode);
if (j > k) {
for (i = 0; i <= (j - k); ++i) {
int k2 = compare_part(exit_alt_charset_mode, off + i);
if (k2 != 0) {
found = TRUE;
chop_out(off, i, i + k2);
break;
}
}
}
}
/*
* SGR 10 would reset to normal font.
*/
if (!found) {
if ((i = is_csi(off)) != 0
&& off[strlen(off) - 1] == 'm') {
TR(TRACE_DATABASE, ("looking for SGR 10 in %s",
_nc_visbuf(off)));
tmp = skip_zero(off + i);
if (tmp[0] == '1'
&& skip_zero(tmp + 1) != tmp + 1) {
i = tmp - off;
if (off[i - 1] == ';')
i--;
j = skip_zero(tmp + 1) - off;
i = chop_out(off, i, j);
found = TRUE;
}
}
}
if (!found
&& (tmp = strstr(end, off)) != 0
&& strcmp(end, off) != 0) {
i = tmp - end;
j = strlen(off);
tmp = strdup(end);
chop_out(tmp, i, j);
free(off);
result = tmp;
}
TR(TRACE_DATABASE, ("...adjusted sgr0 : %s", _nc_visbuf(result)));
if (!strcmp(result, exit_attribute_mode)) {
TR(TRACE_DATABASE, ("...same result, discard"));
free(result);
result = exit_attribute_mode;
}
} else {
/*
* Either the sgr does not reference alternate character set,
* or it is incorrect. That's too hard to decide right now.
*/
free(off);
}
free(end);
free(on);
} else {
/*
* Possibly some applications are confused if sgr0 contains rmacs,
* but that would be a different bug report -TD
*/
}
returnPtr(result);
}

View File

@ -0,0 +1,80 @@
/****************************************************************************
* Copyright (c) 2003-2004,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/*
** Support functions for wide/narrow conversion.
*/
#include <curses.priv.h>
MODULE_ID("$Id: charable.c,v 1.4 2005/04/16 18:08:56 tom Exp $")
NCURSES_EXPORT(bool) _nc_is_charable(wchar_t ch)
{
bool result;
#if HAVE_WCTOB
result = (wctob((wint_t) ch) == ch);
#else
result = (_nc_to_char(ch) >= 0);
#endif
return result;
}
NCURSES_EXPORT(int) _nc_to_char(wint_t ch)
{
int result;
#if HAVE_WCTOB
result = wctob(ch);
#elif HAVE_WCTOMB
char temp[MB_LEN_MAX];
result = wctomb(temp, ch);
if (strlen(temp) == 1)
result = UChar(temp[0]);
else
result = -1;
#endif
return result;
}
NCURSES_EXPORT(wint_t) _nc_to_widechar(int ch)
{
wint_t result;
#if HAVE_BTOWC
result = btowc(ch);
#elif HAVE_MBTOWC
wchar_t convert;
char temp[2];
temp[0] = ch;
temp[1] = '\0';
if (mbtowc(&convert, temp, 1) >= 0)
result = convert;
else
result = WEOF;
#endif
return result;
}

View File

@ -0,0 +1,113 @@
/****************************************************************************
* Copyright (c) 2004,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/*
** lib_add_wch.c
**
** The routine wadd_wch().
**
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_add_wch.c,v 1.6 2006/12/02 21:19:17 tom Exp $")
NCURSES_EXPORT(int)
wadd_wch(WINDOW *win, const cchar_t *wch)
{
PUTC_DATA;
int n;
int code = ERR;
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"), win,
_tracech_t(wch)));
if (win != 0) {
PUTC_INIT;
for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
attr_t attrs = (wch->attr & A_ATTRIBUTES);
if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0')
break;
if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
code = ERR;
if (is8bits(PUTC_ch))
code = waddch(win, UChar(PUTC_ch) | attrs);
break;
}
for (n = 0; n < PUTC_n; n++) {
if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) {
break;
}
}
if (code == ERR)
break;
}
}
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}
NCURSES_EXPORT(int)
wecho_wchar(WINDOW *win, const cchar_t *wch)
{
PUTC_DATA;
int n;
int code = ERR;
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wecho_wchar(%p, %s)"), win,
_tracech_t(wch)));
if (win != 0) {
PUTC_INIT;
for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
attr_t attrs = (wch->attr & A_ATTRIBUTES);
if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0')
break;
if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
code = ERR;
if (is8bits(PUTC_ch))
code = waddch(win, UChar(PUTC_ch) | attrs);
break;
}
for (n = 0; n < PUTC_n; n++) {
if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) {
break;
}
}
if (code == ERR)
break;
}
wrefresh(win);
}
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}

View File

@ -0,0 +1,57 @@
/****************************************************************************
* Copyright (c) 2004 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: lib_pecho_wchar.c,v 1.1 2004/01/03 21:42:01 tom Exp $")
NCURSES_EXPORT(int)
pecho_wchar(WINDOW *pad, const cchar_t * wch)
{
T((T_CALLED("pecho_wchar(%p, %s)"), pad, _tracech_t(wch)));
if (pad == 0)
returnCode(ERR);
if (!(pad->_flags & _ISPAD))
returnCode(wecho_wchar(pad, wch));
wadd_wch(pad, wch);
prefresh(pad, pad->_pad._pad_y,
pad->_pad._pad_x,
pad->_pad._pad_top,
pad->_pad._pad_left,
pad->_pad._pad_bottom,
pad->_pad._pad_right);
returnCode(OK);
}

View File

@ -0,0 +1,72 @@
/****************************************************************************
* Copyright (c) 2003-2004,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey *
****************************************************************************/
/*
* lib_slk_wset.c
* Set soft label text.
*/
#include <curses.priv.h>
#if HAVE_WCTYPE_H
#include <wctype.h>
#endif
MODULE_ID("$Id: lib_slk_wset.c,v 1.11 2005/01/16 01:03:53 tom Exp $")
NCURSES_EXPORT(int)
slk_wset(int i, const wchar_t *astr, int format)
{
int result = ERR;
size_t arglen;
const wchar_t *str;
char *mystr;
mbstate_t state;
T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format));
init_mb(state);
str = astr;
if ((arglen = wcsrtombs(NULL, &str, 0, &state)) != (size_t) -1) {
if ((mystr = (char *) _nc_doalloc(0, arglen + 1)) != 0) {
str = astr;
if (wcsrtombs(mystr, &str, arglen, &state) != (size_t) -1) {
/* glibc documentation claims that the terminating L'\0'
* is written, but it is not...
*/
mystr[arglen] = 0;
result = slk_set(i, mystr, format);
}
free(mystr);
}
}
returnCode(result);
}

View File

@ -0,0 +1,182 @@
/****************************************************************************
* Copyright (c) 2002,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 2002,2005 *
****************************************************************************/
/* LINTLIBRARY */
/* ./panel.c */
#include "panel.priv.h"
#undef _nc_retrace_panel
PANEL *_nc_retrace_panel(
PANEL *pan)
{ return(*(PANEL **)0); }
#undef _nc_my_visbuf
const char *_nc_my_visbuf(
const void *ptr)
{ return(*(const char **)0); }
#undef _nc_dPanel
void _nc_dPanel(
const char *text,
const PANEL *pan)
{ /* void */ }
#undef _nc_dStack
void _nc_dStack(
const char *fmt,
int num,
const PANEL *pan)
{ /* void */ }
#undef _nc_Wnoutrefresh
void _nc_Wnoutrefresh(
const PANEL *pan)
{ /* void */ }
#undef _nc_Touchpan
void _nc_Touchpan(
const PANEL *pan)
{ /* void */ }
#undef _nc_Touchline
void _nc_Touchline(
const PANEL *pan,
int start,
int count)
{ /* void */ }
/* ./p_above.c */
#undef panel_above
PANEL *panel_above(
const PANEL *pan)
{ return(*(PANEL **)0); }
/* ./p_below.c */
#undef panel_below
PANEL *panel_below(
const PANEL *pan)
{ return(*(PANEL **)0); }
/* ./p_bottom.c */
#undef bottom_panel
int bottom_panel(
PANEL *pan)
{ return(*(int *)0); }
/* ./p_delete.c */
#undef del_panel
int del_panel(
PANEL *pan)
{ return(*(int *)0); }
/* ./p_hide.c */
#undef hide_panel
int hide_panel(
PANEL *pan)
{ return(*(int *)0); }
/* ./p_hidden.c */
#undef panel_hidden
int panel_hidden(
const PANEL *pan)
{ return(*(int *)0); }
/* ./p_move.c */
#undef move_panel
int move_panel(
PANEL *pan,
int starty,
int startx)
{ return(*(int *)0); }
/* ./p_new.c */
#undef new_panel
PANEL *new_panel(
WINDOW *win)
{ return(*(PANEL **)0); }
/* ./p_replace.c */
#undef replace_panel
int replace_panel(
PANEL *pan,
WINDOW *win)
{ return(*(int *)0); }
/* ./p_show.c */
#undef show_panel
int show_panel(
PANEL *pan)
{ return(*(int *)0); }
/* ./p_top.c */
#undef top_panel
int top_panel(
PANEL *pan)
{ return(*(int *)0); }
/* ./p_update.c */
#undef update_panels
void update_panels(void)
{ /* void */ }
/* ./p_user.c */
#undef set_panel_userptr
int set_panel_userptr(
PANEL *pan,
void *uptr)
{ return(*(int *)0); }
#undef panel_userptr
void *panel_userptr(
const PANEL *pan)
{ return(*(void **)0); }
/* ./p_win.c */
#undef panel_window
WINDOW *panel_window(
const PANEL *pan)
{ return(*(WINDOW **)0); }

View File

@ -0,0 +1,240 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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.
*/
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "archive.h"
struct read_file_data {
int fd;
size_t block_size;
void *buffer;
mode_t st_mode; /* Mode bits for opened file. */
char filename[1]; /* Must be last! */
};
static int file_close(struct archive *, void *);
static int file_open(struct archive *, void *);
static ssize_t file_read(struct archive *, void *, const void **buff);
#if ARCHIVE_API_VERSION < 2
static ssize_t file_skip(struct archive *, void *, size_t request);
#else
static off_t file_skip(struct archive *, void *, off_t request);
#endif
int
archive_read_open_file(struct archive *a, const char *filename,
size_t block_size)
{
return (archive_read_open_filename(a, filename, block_size));
}
int
archive_read_open_filename(struct archive *a, const char *filename,
size_t block_size)
{
struct read_file_data *mine;
if (filename == NULL || filename[0] == '\0') {
mine = (struct read_file_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
mine->filename[0] = '\0';
} else {
mine = (struct read_file_data *)malloc(sizeof(*mine) + strlen(filename));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
strcpy(mine->filename, filename);
}
mine->block_size = block_size;
mine->buffer = NULL;
mine->fd = -1;
return (archive_read_open2(a, mine, file_open, file_read, file_skip, file_close));
}
static int
file_open(struct archive *a, void *client_data)
{
struct read_file_data *mine = (struct read_file_data *)client_data;
struct stat st;
mine->buffer = malloc(mine->block_size);
if (mine->buffer == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
if (mine->filename[0] != '\0')
mine->fd = open(mine->filename, O_RDONLY);
else
mine->fd = 0; /* Fake "open" for stdin. */
if (mine->fd < 0) {
archive_set_error(a, errno, "Failed to open '%s'",
mine->filename);
return (ARCHIVE_FATAL);
}
if (fstat(mine->fd, &st) == 0) {
/* If we're reading a file from disk, ensure that we don't
overwrite it with an extracted file. */
if (S_ISREG(st.st_mode))
archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
/* Remember mode so close can decide whether to flush. */
mine->st_mode = st.st_mode;
} else {
if (mine->filename[0] == '\0')
archive_set_error(a, errno, "Can't stat stdin");
else
archive_set_error(a, errno, "Can't stat '%s'",
mine->filename);
return (ARCHIVE_FATAL);
}
return (0);
}
static ssize_t
file_read(struct archive *a, void *client_data, const void **buff)
{
struct read_file_data *mine = (struct read_file_data *)client_data;
ssize_t bytes_read;
*buff = mine->buffer;
bytes_read = read(mine->fd, mine->buffer, mine->block_size);
if (bytes_read < 0) {
if (mine->filename[0] == '\0')
archive_set_error(a, errno, "Error reading stdin");
else
archive_set_error(a, errno, "Error reading '%s'",
mine->filename);
}
return (bytes_read);
}
#if ARCHIVE_API_VERSION < 2
static ssize_t
file_skip(struct archive *a, void *client_data, size_t request)
#else
static off_t
file_skip(struct archive *a, void *client_data, off_t request)
#endif
{
struct read_file_data *mine = (struct read_file_data *)client_data;
off_t old_offset, new_offset;
/* Reduce request to the next smallest multiple of block_size */
request = (request / mine->block_size) * mine->block_size;
/*
* Hurray for lazy evaluation: if the first lseek fails, the second
* one will not be executed.
*/
if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) < 0) ||
((new_offset = lseek(mine->fd, request, SEEK_CUR)) < 0))
{
if (errno == ESPIPE)
{
/*
* Failure to lseek() can be caused by the file
* descriptor pointing to a pipe, socket or FIFO.
* Return 0 here, so the compression layer will use
* read()s instead to advance the file descriptor.
* It's slower of course, but works as well.
*/
return (0);
}
/*
* There's been an error other than ESPIPE. This is most
* likely caused by a programmer error (too large request)
* or a corrupted archive file.
*/
if (mine->filename[0] == '\0')
/*
* Should never get here, since lseek() on stdin ought
* to return an ESPIPE error.
*/
archive_set_error(a, errno, "Error seeking in stdin");
else
archive_set_error(a, errno, "Error seeking in '%s'",
mine->filename);
return (-1);
}
return (new_offset - old_offset);
}
static int
file_close(struct archive *a, void *client_data)
{
struct read_file_data *mine = (struct read_file_data *)client_data;
(void)a; /* UNUSED */
/*
* Sometimes, we should flush the input before closing.
* Regular files: faster to just close without flush.
* Devices: must not flush (user might need to
* read the "next" item on a non-rewind device).
* Pipes and sockets: must flush (otherwise, the
* program feeding the pipe or socket may complain).
* Here, I flush everything except for regular files and
* device nodes.
*/
if (!S_ISREG(mine->st_mode)
&& !S_ISCHR(mine->st_mode)
&& !S_ISBLK(mine->st_mode)) {
ssize_t bytesRead;
do {
bytesRead = read(mine->fd, mine->buffer,
mine->block_size);
} while (bytesRead > 0);
}
/* If a named file was opened, then it needs to be closed. */
if (mine->filename[0] != '\0')
close(mine->fd);
if (mine->buffer != NULL)
free(mine->buffer);
free(mine);
return (ARCHIVE_OK);
}

View File

@ -0,0 +1,156 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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.
*/
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "archive.h"
/*
* Glue to read an archive from a block of memory.
*
* This is mostly a huge help in building test harnesses;
* test programs can build archives in memory and read them
* back again without having to mess with files on disk.
*/
struct read_memory_data {
unsigned char *buffer;
unsigned char *end;
ssize_t read_size;
};
static int memory_read_close(struct archive *, void *);
static int memory_read_open(struct archive *, void *);
#if ARCHIVE_API_VERSION < 2
static ssize_t memory_read_skip(struct archive *, void *, size_t request);
#else
static off_t memory_read_skip(struct archive *, void *, off_t request);
#endif
static ssize_t memory_read(struct archive *, void *, const void **buff);
int
archive_read_open_memory(struct archive *a, void *buff, size_t size)
{
return archive_read_open_memory2(a, buff, size, size);
}
/*
* Don't use _open_memory2() in production code; the archive_read_open_memory()
* version is the one you really want. This is just here so that
* test harnesses can exercise block operations inside the library.
*/
int
archive_read_open_memory2(struct archive *a, void *buff,
size_t size, size_t read_size)
{
struct read_memory_data *mine;
mine = (struct read_memory_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
memset(mine, 0, sizeof(*mine));
mine->buffer = (unsigned char *)buff;
mine->end = mine->buffer + size;
mine->read_size = read_size;
return (archive_read_open2(a, mine, memory_read_open,
memory_read, memory_read_skip, memory_read_close));
}
/*
* There's nothing to open.
*/
static int
memory_read_open(struct archive *a, void *client_data)
{
(void)a; /* UNUSED */
(void)client_data; /* UNUSED */
return (ARCHIVE_OK);
}
/*
* This is scary simple: Just advance a pointer. Limiting
* to read_size is not technically necessary, but it exercises
* more of the internal logic when used with a small block size
* in a test harness. Production use should not specify a block
* size; then this is much faster.
*/
static ssize_t
memory_read(struct archive *a, void *client_data, const void **buff)
{
struct read_memory_data *mine = (struct read_memory_data *)client_data;
ssize_t size;
(void)a; /* UNUSED */
*buff = mine->buffer;
size = mine->end - mine->buffer;
if (size > mine->read_size)
size = mine->read_size;
mine->buffer += size;
return (size);
}
/*
* Advancing is just as simple. Again, this is doing more than
* necessary in order to better exercise internal code when used
* as a test harness.
*/
#if ARCHIVE_API_VERSION < 2
static ssize_t
memory_read_skip(struct archive *a, void *client_data, size_t skip)
#else
static off_t
memory_read_skip(struct archive *a, void *client_data, off_t skip)
#endif
{
struct read_memory_data *mine = (struct read_memory_data *)client_data;
(void)a; /* UNUSED */
if (mine->buffer + skip > mine->end)
skip = mine->end - mine->buffer;
/* Round down to block size. */
skip /= mine->read_size;
skip *= mine->read_size;
mine->buffer += skip;
return (skip);
}
/*
* Close is just cleaning up our one small bit of data.
*/
static int
memory_read_close(struct archive *a, void *client_data)
{
struct read_memory_data *mine = (struct read_memory_data *)client_data;
(void)a; /* UNUSED */
free(mine);
return (ARCHIVE_OK);
}

View File

@ -0,0 +1,175 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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.
*/
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "archive.h"
struct write_file_data {
int fd;
char filename[1];
};
static int file_close(struct archive *, void *);
static int file_open(struct archive *, void *);
static ssize_t file_write(struct archive *, void *, const void *buff, size_t);
int
archive_write_open_file(struct archive *a, const char *filename)
{
return (archive_write_open_filename(a, filename));
}
int
archive_write_open_filename(struct archive *a, const char *filename)
{
struct write_file_data *mine;
if (filename == NULL || filename[0] == '\0') {
mine = (struct write_file_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
mine->filename[0] = '\0'; /* Record that we're using stdout. */
} else {
mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
strcpy(mine->filename, filename);
}
mine->fd = -1;
return (archive_write_open(a, mine,
file_open, file_write, file_close));
}
static int
file_open(struct archive *a, void *client_data)
{
int flags;
struct write_file_data *mine;
struct stat st;
mine = (struct write_file_data *)client_data;
flags = O_WRONLY | O_CREAT | O_TRUNC;
/*
* Open the file.
*/
if (mine->filename[0] != '\0') {
mine->fd = open(mine->filename, flags, 0666);
if (mine->fd < 0) {
archive_set_error(a, errno, "Failed to open '%s'",
mine->filename);
return (ARCHIVE_FATAL);
}
} else {
/*
* NULL filename is stdout.
*/
mine->fd = 1;
/* By default, pad archive when writing to stdout. */
if (archive_write_get_bytes_in_last_block(a) < 0)
archive_write_set_bytes_in_last_block(a, 0);
}
if (fstat(mine->fd, &st) != 0) {
archive_set_error(a, errno, "Couldn't stat '%s'",
mine->filename);
return (ARCHIVE_FATAL);
}
/*
* Set up default last block handling.
*/
if (archive_write_get_bytes_in_last_block(a) < 0) {
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) ||
S_ISFIFO(st.st_mode))
/* Pad last block when writing to device or FIFO. */
archive_write_set_bytes_in_last_block(a, 0);
else
/* Don't pad last block otherwise. */
archive_write_set_bytes_in_last_block(a, 1);
}
/*
* If the output file is a regular file, don't add it to
* itself. If it's a device file, it's okay to add the device
* entry to the output archive.
*/
if (S_ISREG(st.st_mode))
archive_write_set_skip_file(a, st.st_dev, st.st_ino);
return (ARCHIVE_OK);
}
static ssize_t
file_write(struct archive *a, void *client_data, const void *buff, size_t length)
{
struct write_file_data *mine;
ssize_t bytesWritten;
mine = (struct write_file_data *)client_data;
bytesWritten = write(mine->fd, buff, length);
if (bytesWritten <= 0) {
archive_set_error(a, errno, "Write error");
return (-1);
}
return (bytesWritten);
}
static int
file_close(struct archive *a, void *client_data)
{
struct write_file_data *mine = (struct write_file_data *)client_data;
(void)a; /* UNUSED */
if (mine->filename[0] != '\0')
close(mine->fd);
free(mine);
return (ARCHIVE_OK);
}

View File

@ -0,0 +1,126 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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.
*/
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "archive.h"
/*
* This is a little tricky. I used to allow the
* compression handling layer to fork the compressor,
* which means this write function gets invoked in
* a separate process. That would, of course, make it impossible
* to actually use the data stored into memory here.
* Fortunately, none of the compressors fork today and
* I'm reluctant to use that route in the future but, if
* forking compressors ever do reappear, this will have
* to get a lot more complicated.
*/
struct write_memory_data {
size_t used;
size_t size;
size_t * client_size;
unsigned char * buff;
};
static int memory_write_close(struct archive *, void *);
static int memory_write_open(struct archive *, void *);
static ssize_t memory_write(struct archive *, void *, const void *buff, size_t);
/*
* Client provides a pointer to a block of memory to receive
* the data. The 'size' param both tells us the size of the
* client buffer and lets us tell the client the final size.
*/
int
archive_write_open_memory(struct archive *a, void *buff, size_t buffSize, size_t *used)
{
struct write_memory_data *mine;
mine = (struct write_memory_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
memset(mine, 0, sizeof(*mine));
mine->buff = buff;
mine->size = buffSize;
mine->client_size = used;
return (archive_write_open(a, mine,
memory_write_open, memory_write, memory_write_close));
}
static int
memory_write_open(struct archive *a, void *client_data)
{
struct write_memory_data *mine;
mine = client_data;
mine->used = 0;
if (mine->client_size != NULL)
*mine->client_size = mine->used;
/* Disable padding if it hasn't been set explicitly. */
if (-1 == archive_write_get_bytes_in_last_block(a))
archive_write_set_bytes_in_last_block(a, 1);
return (ARCHIVE_OK);
}
/*
* Copy the data into the client buffer.
* Note that we update mine->client_size on every write.
* In particular, this means the client can follow exactly
* how much has been written into their buffer at any time.
*/
static ssize_t
memory_write(struct archive *a, void *client_data, const void *buff, size_t length)
{
struct write_memory_data *mine;
mine = client_data;
if (mine->used + length > mine->size) {
archive_set_error(a, ENOMEM, "Buffer exhausted");
return (ARCHIVE_FATAL);
}
memcpy(mine->buff + mine->used, buff, length);
mine->used += length;
if (mine->client_size != NULL)
*mine->client_size = mine->used;
return (length);
}
static int
memory_write_close(struct archive *a, void *client_data)
{
struct write_memory_data *mine;
(void)a; /* UNUSED */
mine = client_data;
free(mine);
return (ARCHIVE_OK);
}

View File

@ -0,0 +1,92 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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.
*
* $FreeBSD$
*/
/* FreeBSD 5.0 and later have ACL support. */
#if __FreeBSD__ > 4
#define HAVE_ACL_CREATE_ENTRY 1
#define HAVE_ACL_INIT 1
#define HAVE_ACL_SET_FD 1
#define HAVE_ACL_SET_FD_NP 1
#define HAVE_ACL_SET_FILE 1
#define HAVE_ACL_USER 1
#endif
#define HAVE_BZLIB_H 1
#define HAVE_CHFLAGS 1
#define HAVE_DECL_STRERROR_R 1
#define HAVE_EFTYPE 1
#define HAVE_EILSEQ 1
#define HAVE_ERRNO_H 1
#define HAVE_FCHDIR 1
#define HAVE_FCHFLAGS 1
#define HAVE_FCHMOD 1
#define HAVE_FCHOWN 1
#define HAVE_FCNTL_H 1
#define HAVE_FSEEKO 1
#define HAVE_FUTIMES 1
#define HAVE_GRP_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_LCHFLAGS 1
#define HAVE_LCHMOD 1
#define HAVE_LCHOWN 1
#define HAVE_LIMITS_H 1
#define HAVE_LUTIMES 1
#define HAVE_MALLOC 1
#define HAVE_MEMMOVE 1
#define HAVE_MEMSET 1
#define HAVE_MKDIR 1
#define HAVE_MKFIFO 1
#define HAVE_PWD_H 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRCHR 1
#define HAVE_STRDUP 1
#define HAVE_STRERROR 1
#define HAVE_STRERROR_R 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_STRRCHR 1
#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
#define HAVE_STRUCT_STAT_ST_RDEV 1
#define HAVE_SYS_ACL_H 1
#define HAVE_SYS_IOCTL_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_WAIT_H 1
#define HAVE_TIMEGM 1
#define HAVE_UNISTD_H 1
#define HAVE_WCHAR_H 1
#define HAVE_ZLIB_H 1
#define STDC_HEADERS 1
#define TIME_WITH_SYS_TIME 1
/* FreeBSD 4 and earlier lack intmax_t/uintmax_t */
#if __FreeBSD__ < 5
#define intmax_t int64_t
#define uintmax_t uint64_t
#endif

101
lib/msun/src/s_modfl.c Normal file
View File

@ -0,0 +1,101 @@
/*-
* Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* Derived from s_modf.c, which has the following Copyright:
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
* $FreeBSD$
*/
#include <float.h>
#include <math.h>
#include <sys/types.h>
#include "fpmath.h"
#if LDBL_MANL_SIZE > 32
#define MASK ((uint64_t)-1)
#else
#define MASK ((uint32_t)-1)
#endif
/* Return the last n bits of a word, representing the fractional part. */
#define GETFRAC(bits, n) ((bits) & ~(MASK << (n)))
/* The number of fraction bits in manh, not counting the integer bit */
#define HIBITS (LDBL_MANT_DIG - LDBL_MANL_SIZE)
static const long double zero[] = { 0.0L, -0.0L };
long double
modfl(long double x, long double *iptr)
{
union IEEEl2bits ux;
int e;
ux.e = x;
e = ux.bits.exp - LDBL_MAX_EXP + 1;
if (e < HIBITS) { /* Integer part is in manh. */
if (e < 0) { /* |x|<1 */
*iptr = zero[ux.bits.sign];
return (x);
} else {
if ((GETFRAC(ux.bits.manh, HIBITS - 1 - e) |
ux.bits.manl) == 0) { /* X is an integer. */
*iptr = x;
return (zero[ux.bits.sign]);
} else {
/* Clear all but the top e+1 bits. */
ux.bits.manh >>= HIBITS - 1 - e;
ux.bits.manh <<= HIBITS - 1 - e;
ux.bits.manl = 0;
*iptr = ux.e;
return (x - ux.e);
}
}
} else if (e >= LDBL_MANT_DIG - 1) { /* x has no fraction part. */
*iptr = x;
if (x != x) /* Handle NaNs. */
return (x);
return (zero[ux.bits.sign]);
} else { /* Fraction part is in manl. */
if (GETFRAC(ux.bits.manl, LDBL_MANT_DIG - 1 - e) == 0) {
/* x is integral. */
*iptr = x;
return (zero[ux.bits.sign]);
} else {
/* Clear all but the top e+1 bits. */
ux.bits.manl >>= LDBL_MANT_DIG - 1 - e;
ux.bits.manl <<= LDBL_MANT_DIG - 1 - e;
*iptr = ux.e;
return (x - ux.e);
}
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* @(#)pathnames.h 8.1 (Berkeley) 6/4/93
* $FreeBSD$
*/
#define _PATH_DEF ".termcap /usr/share/misc/termcap"
#define _PATH_DEF_SEC "/usr/share/misc/termcap"

View File

@ -0,0 +1,262 @@
/* A portion of this file is from ncurses: */
/***************************************************************************
* COPYRIGHT NOTICE *
****************************************************************************
* ncurses is copyright (C) 1992-1995 *
* Zeyd M. Ben-Halim *
* zmbenhal@netcom.com *
* Eric S. Raymond *
* esr@snark.thyrsus.com *
* *
* Permission is hereby granted to reproduce and distribute ncurses *
* by any means and for any fee, whether alone or as part of a *
* larger distribution, in source or in binary form, PROVIDED *
* this notice is included with any such distribution, and is not *
* removed from any of its header files. Mention of ncurses in any *
* applications linked with it is highly appreciated. *
* *
* ncurses comes AS IS with no warranty, implied or expressed. *
* *
***************************************************************************/
#include <curses.priv.h>
#include <string.h>
#include <term.h>
#include <tic.h>
#include <term_entry.h>
/* The rest is from BSD */
/*
* Copyright (c) 1980, 1993
* The Regents of the University of California. 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
static const char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include "pathnames.h"
#define PBUFSIZ MAXPATHLEN /* max length of filename path */
#define PVECSIZ 32 /* max number of names in path */
#define TBUFSIZ 1024 /* max length of _nc_tgetent buffer */
char _nc_termcap[TBUFSIZ + 1]; /* Last getcap, provided to tgetent() emul */
/*
* termcap - routines for dealing with the terminal capability data base
*
* BUG: Should use a "last" pointer in tbuf, so that searching
* for capabilities alphabetically would not be a n**2/2
* process when large numbers of capabilities are given.
* Note: If we add a last pointer now we will screw up the
* tc capability. We really should compile termcap.
*
* Essentially all the work here is scanning and decoding escapes
* in string capabilities. We don't use stdio because the editor
* doesn't, and because living w/o it is not hard.
*/
/*
* Get an entry for terminal name in buffer _nc_termcap from the termcap
* file.
*/
int
_nc_read_termcap_entry(const char *const name, TERMTYPE *const tp)
{
ENTRY *ep;
char *p;
char *cp;
char *dummy;
char **fname;
char *home;
int i;
char pathbuf[PBUFSIZ]; /* holds raw path of filenames */
char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
char **pvec; /* holds usable tail of path vector */
char *termpath;
_nc_termcap[0] = '\0'; /* in case */
dummy = NULL;
fname = pathvec;
pvec = pathvec;
p = pathbuf;
cp = getenv("TERMCAP");
/*
* TERMCAP can have one of two things in it. It can be the
* name of a file to use instead of /etc/termcap. In this
* case it better start with a "/". Or it can be an entry to
* use so we don't have to read the file. In this case it
* has to already have the newlines crunched out. If TERMCAP
* does not hold a file name then a path of names is searched
* instead. The path is found in the TERMPATH variable, or
* becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists.
*/
if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */
if ( (termpath = getenv("TERMPATH")) )
strncpy(pathbuf, termpath, PBUFSIZ);
else {
if ( (home = getenv("HOME")) ) {/* set up default */
strncpy(pathbuf, home, PBUFSIZ - 1); /* $HOME first */
pathbuf[PBUFSIZ - 2] = '\0'; /* -2 because we add a slash */
p += strlen(pathbuf); /* path, looking in */
*p++ = '/';
} /* if no $HOME look in current directory */
strncpy(p, _PATH_DEF, PBUFSIZ - (p - pathbuf));
}
}
else /* user-defined name in TERMCAP */
strncpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */
/* For safety */
if (issetugid())
strcpy(pathbuf, _PATH_DEF_SEC);
pathbuf[PBUFSIZ - 1] = '\0';
*fname++ = pathbuf; /* tokenize path into vector of names */
while (*++p)
if (*p == ' ' || *p == ':') {
*p = '\0';
while (*++p)
if (*p != ' ' && *p != ':')
break;
if (*p == '\0')
break;
*fname++ = p;
if (fname >= pathvec + PVECSIZ) {
fname--;
break;
}
}
*fname = (char *) 0; /* mark end of vector */
if (cp && *cp && *cp != '/')
if (cgetset(cp) < 0)
return(-2);
i = cgetent(&dummy, pathvec, (char *)name);
if (i == 0) {
char *pd, *ps, *tok, *s, *tcs;
size_t len;
pd = _nc_termcap;
ps = dummy;
if ((tok = strchr(ps, ':')) == NULL) {
len = strlen(ps);
if (len >= TBUFSIZ)
i = -1;
else
strcpy(pd, ps);
goto done;
}
len = tok - ps + 1;
if (pd + len + 1 - _nc_termcap >= TBUFSIZ) {
i = -1;
goto done;
}
memcpy(pd, ps, len);
ps += len;
pd += len;
*pd = '\0';
tcs = pd - 1;
for (;;) {
while ((tok = strsep(&ps, ":")) != NULL &&
*(tok - 2) != '\\' &&
(*tok == '\0' || *tok == '\\' || !isgraph(UChar(*tok))))
;
if (tok == NULL)
break;
for (s = tcs; s != NULL && s[1] != '\0';
s = strchr(s, ':')) {
s++;
if (s[0] == tok[0] && s[1] == tok[1])
goto skip_it;
}
len = strlen(tok);
if (pd + len + 1 - _nc_termcap >= TBUFSIZ) {
i = -1;
break;
}
memcpy(pd, tok, len);
pd += len;
*pd++ = ':';
*pd = '\0';
skip_it: ;
}
}
done:
if (dummy)
free(dummy);
/*
* From here on is ncurses-specific glue code
*/
if (i < 0)
return(TGETENT_ERR);
_nc_set_source("TERMCAP");
_nc_read_entry_source((FILE *)NULL, _nc_termcap, FALSE, TRUE, NULLHOOK);
if (_nc_head == (ENTRY *)NULL)
return(TGETENT_ERR);
/* resolve all use references */
_nc_resolve_uses2(TRUE, FALSE);
for_entry_list(ep)
if (_nc_name_match(ep->tterm.term_names, name, "|:"))
{
/*
* Make a local copy of the terminal capabilities, delinked
* from the list.
*/
memcpy(tp, &ep->tterm, sizeof(TERMTYPE));
_nc_delink_entry(_nc_head, &(ep->tterm));
free(ep);
_nc_free_entries(_nc_head);
_nc_head = _nc_tail = NULL; /* do not reuse! */
return TGETENT_YES; /* OK */
}
_nc_free_entries(_nc_head);
_nc_head = _nc_tail = NULL; /* do not reuse! */
return(TGETENT_NO); /* not found */
}

159
share/man/man4/ng_deflate.4 Normal file
View File

@ -0,0 +1,159 @@
.\"
.\" Author: Alexander Motin <mav@alkar.net>
.\"
.\" Copyright (c) 2006, Alexander Motin <mav@alkar.net>
.\" 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 unmodified, this list of conditions, and the following
.\" disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
.\"
.\" $FreeBSD$
.\"
.Dd December 23, 2006
.Dt NG_DEFLATE 4
.Os
.Sh NAME
.Nm ng_deflate
.Nd Deflate PPP compression (RFC 1979) netgraph node type
.Sh SYNOPSIS
.In sys/types.h
.In netgraph/ng_deflate.h
.Sh DESCRIPTION
The
.Nm deflate
node type implements the Deflate sub-protocols of the Compression Control
Protocol (CCP).
.Pp
The node has two hooks,
.Va comp
for compression and
.Va decomp
for decompression.
Only one of them can be connected at the same time, specifying node's
operation mode.
Typically that hooks would be connected to the
.Xr ng_ppp 4
node type hook of the same name.
Corresponding
.Xr ng_ppp 4
node hook must be switched to
.Dv NG_PPP_DECOMPRESS_FULL
mode to permit sending uncompressed frames.
.Sh HOOKS
This node type supports the following hooks:
.Pp
.Bl -tag -compact -width decomp
.It Va comp
Connection to
.Xr ng_ppp 4
.Va comp
hook.
Incoming frames are compressed (if possible) and sent back out the same hook.
.It Va decomp
Connection to
.Xr ng_ppp 4
.Va decomp
hook.
Incoming frames are decompressed (if they are compressed), and sent
back out the same hook.
.El
.Pp
Only one hook can be connected at the same time, specifying node's
operation mode.
.Sh CONTROL MESSAGES
This node type supports the generic control messages, plus the following:
.Bl -tag -width foo
.It Dv NGM_DEFLATE_CONFIG Pq Li config
This command resets and configures the node for a session
(i.e., for compression or decompression).
This command takes a
.Vt "struct ng_deflate_config"
as an argument:
.Bd -literal -offset 0n
struct ng_deflate_config {
u_char enable; /* node enabled */
u_char windowBits; /* log2(Window size) */
};
.Ed
The
.Fa enabled
field enables traffic flow through the node.
The
.Fa windowBits
specify compression windows size as negotiated by the
Compression Control Protocol (CCP) in PPP.
The
.It Dv NGM_DEFLATE_RESETREQ Pq Li resetreq
This message contains no arguments, and is bi-directional.
If an error is detected during decompression, this message is sent by the
node to the originator of the
.Dv NGM_DEFLATE_CONFIG
message that initiated the session.
The receiver should respond by sending a PPP CCP Reset-Request to the peer.
.Pp
This message may also be received by this node type when a CCP Reset-Request
or Reset-Ack is received by the local PPP entity.
The node will respond by flushing its compression state so the sides
can resynchronize.
.It Dv NGM_DEFLATE_GET_STATS Pq Li getstats
This control message obtains statistics for a given hook.
The statistics are returned in
.Vt "struct ng_deflate_stats" :
.Bd -literal
struct ng_deflate_stats {
uint64_t FramesPlain;
uint64_t FramesComp;
uint64_t FramesUncomp;
uint64_t InOctets;
uint64_t OutOctets;
uint64_t Errors;
};
.Ed
.It Dv NGM_DEFLATE_CLR_STATS Pq Li clrstats
This control message clears statistics for a given hook.
.It Dv NGM_DEFLATE_GETCLR_STATS Pq Li getclrstats
This control message obtains and clears statistics for a given hook.
.El
.Sh SHUTDOWN
This node shuts down upon receipt of a
.Dv NGM_SHUTDOWN
control message, or when hook have been disconnected.
.Sh SEE ALSO
.Xr netgraph 4 ,
.Xr ng_ppp 4 ,
.Xr ngctl 8
.Rs
.%A J. Woods
.%T "PPP Deflate Protocol"
.%O RFC 1979
.Re
.Rs
.%A W. Simpson
.%T "The Point-to-Point Protocol (PPP)"
.%O RFC 1661
.Re
.Sh AUTHORS
.An Alexander Motin Aq mav@alkar.net
.Sh BUGS
Due to nature of netgraph PPP implementation there are possible race conditions
between data packet and ResetAck CCP packet in case of packet loss. As result,
packet loss can produce bigger performance degradation than supposed by protocol.

145
share/man/man4/ng_pred1.4 Normal file
View File

@ -0,0 +1,145 @@
.\"
.\" Copyright (c) 2006, Alexander Motin <mav@alkar.net>
.\" 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 unmodified, this list of conditions, and the following
.\" disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
.\"
.\" $FreeBSD$
.\"
.Dd December 24, 2006
.Dt NG_PRED1 4
.Os
.Sh NAME
.Nm ng_pred1
.Nd Predictor-1 PPP compression (RFC 1978) netgraph node type
.Sh SYNOPSIS
.In sys/types.h
.In netgraph/ng_pred1.h
.Sh DESCRIPTION
The
.Nm pred1
node type implements the Predictor-1 sub-protocols of the Compression Control
Protocol (CCP).
.Pp
The node has two hooks,
.Va comp
for compression and
.Va decomp
for decompression.
Only one of them can be connected at the same time, specifying node's
operation mode.
Typically that hooks would be connected to the
.Xr ng_ppp 4
node type hook of the same name.
.Sh HOOKS
This node type supports the following hooks:
.Pp
.Bl -tag -compact -width decomp
.It Va comp
Connection to
.Xr ng_ppp 4
.Va compress
hook.
Incoming frames are compressed and sent back out the same hook.
.It Va decomp
Connection to
.Xr ng_ppp 4
.Va decompress
hook.
Incoming frames are decompressed and sent back out the same hook.
.El
.Pp
Only one hook can be connected at the same time,
specifying node's operation mode.
.Sh CONTROL MESSAGES
This node type supports the generic control messages, plus the following:
.Bl -tag -width foo
.It Dv NGM_PRED1_CONFIG Pq Li config
This command resets and configures the node for a session
(i.e., for compression or decompression).
This command takes a
.Vt "struct ng_pred1_config"
as an argument:
.Bd -literal -offset 0n
struct ng_pred1_config {
u_char enable; /* node enabled */
};
.Ed
The
.Ft enable
field enables traffic flow through the node.
.It Dv NGM_PRED1_RESETREQ Pq Li resetreq
This message contains no arguments, and is bi-directional.
If an error is detected during decompression, this message is sent by the
node to the originator of the
.Dv NGM_PRED1_CONFIG
message that initiated the session.
The receiver should respond by sending a PPP CCP Reset-Request to the peer.
.Pp
This message may also be received by this node type when a CCP Reset-Request
or Reset-Ack is received by the local PPP entity.
The node will respond by flushing its compression state so the sides
can resynchronize.
.It Dv NGM_PRED1_GET_STATS Pq Li getstats
This control message obtains statistics for a given hook.
The statistics are returned in
.Vt "struct ng_pred1_stats" :
.Bd -literal
struct ng_pred1_stats {
uint64_t FramesPlain;
uint64_t FramesComp;
uint64_t FramesUncomp;
uint64_t InOctets;
uint64_t OutOctets;
uint64_t Errors;
};
.Ed
.It Dv NGM_PRED1_CLR_STATS Pq Li clrstats
This control message clears statistics for a given hook.
.It Dv NGM_PRED1_GETCLR_STATS Pq Li getclrstats
This control message obtains and clears statistics for a given hook.
.El
.Sh SHUTDOWN
This node shuts down upon receipt of a
.Dv NGM_SHUTDOWN
control message, or when hook have been disconnected.
.Sh SEE ALSO
.Xr netgraph 4 ,
.Xr ng_ppp 4 ,
.Xr ngctl 8
.Rs
.%A D. Rand
.%T "PPP Predictor Compression Protocol"
.%O RFC 1978
.Re
.Rs
.%A W. Simpson
.%T "The Point-to-Point Protocol (PPP)"
.%O RFC 1661
.Re
.Sh AUTHORS
.An Alexander Motin Aq mav@alkar.net
.Sh BUGS
Due to nature of netgraph PPP implementation there are possible race conditions
between data packet and ResetAck CCP packet in case of packet loss. As result,
packet loss can produce bigger performance degradation than supposed by protocol.

View File

@ -0,0 +1,85 @@
/* $NetBSD: ixp425_mem.c,v 1.2 2005/12/11 12:16:51 christos Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Steve C. Woodford for Wasabi Systems, Inc.
*
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
* 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <arm/xscale/ixp425/ixp425reg.h>
#include <arm/xscale/ixp425/ixp425var.h>
static uint32_t sdram_64bit[] = {
0x00800000, /* 8M: One 2M x 32 chip */
0x01000000, /* 16M: Two 2M x 32 chips */
0x01000000, /* 16M: Two 4M x 16 chips */
0x02000000, /* 32M: Four 4M x 32 chips */
0, 0, 0, 0
};
static uint32_t sdram_other[] = {
0x02000000, /* 32M: Two 8M x 16 chips */
0x04000000, /* 64M: Four 8M x 16 chips */
0x04000000, /* 64M: Two 16M x 16 chips */
0x08000000, /* 128M: Four 16M x 16 chips */
0x08000000, /* 128M: Two 32M x 16 chips */
0x10000000, /* 256M: Four 32M x 16 chips */
0, 0
};
#define MCU_REG_READ(x) (*(volatile uint32_t *)(IXP425_MCU_VBASE + (x)))
uint32_t
ixp425_sdram_size(void)
{
uint32_t size, sdr_config;
sdr_config = MCU_REG_READ(MCU_SDR_CONFIG);
if (sdr_config & MCU_SDR_CONFIG_64MBIT)
size = sdram_64bit[MCU_SDR_CONFIG_MCONF(sdr_config)];
else
size = sdram_other[MCU_SDR_CONFIG_MCONF(sdr_config)];
if (size == 0) {
printf("** SDR_CONFIG retuns unknown value, using 32M\n");
size = 32 * 1024 * 1024;
}
return (size);
}

View File

@ -0,0 +1,101 @@
/* $NetBSD: ixp425var.h,v 1.10 2006/04/10 03:36:03 simonb Exp $ */
/*
* Copyright (c) 2003
* Ichiro FUKUHARA <ichiro@ichiro.org>.
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Ichiro FUKUHARA.
* 4. The name of the company nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``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 ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD 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.
*
* $FreeBSD$
*
*/
#ifndef _IXP425VAR_H_
#define _IXP425VAR_H_
#include <sys/conf.h>
#include <sys/queue.h>
#include <machine/bus.h>
#include <dev/pci/pcivar.h>
#include <sys/rman.h>
struct ixp425_softc {
device_t sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_gpio_ioh;
bus_space_handle_t sc_exp_ioh;
u_int32_t sc_intrmask;
struct rman sc_irq_rman;
struct rman sc_mem_rman;
bus_dma_tag_t sc_dmat;
};
struct ixppcib_softc {
device_t sc_dev;
u_int sc_bus;
struct resource *sc_csr;
struct resource *sc_mem;
struct rman sc_io_rman;
struct rman sc_mem_rman;
struct rman sc_irq_rman;
struct bus_space sc_pci_memt;
struct bus_space sc_pci_iot;
bus_dma_tag_t sc_dmat;
};
#define EXP_BUS_WRITE_4(sc, reg, data) \
bus_space_write_4(sc->sc_iot, sc->sc_exp_ioh, reg, data)
#define EXP_BUS_READ_4(sc, reg) \
bus_space_read_4(sc->sc_iot, sc->sc_exp_ioh, reg)
#define GPIO_CONF_WRITE_4(sc, reg, data) \
bus_space_write_4(sc->sc_iot, sc->sc_gpio_ioh, reg, data)
#define GPIO_CONF_READ_4(sc, reg) \
bus_space_read_4(sc->sc_iot, sc->sc_gpio_ioh, reg)
extern struct bus_space ixp425_bs_tag;
extern struct bus_space ixp425_a4x_bs_tag;
void ixp425_io_bs_init(bus_space_tag_t, void *);
void ixp425_mem_bs_init(bus_space_tag_t, void *);
uint32_t ixp425_sdram_size(void);
int ixp425_md_route_interrupt(device_t, device_t, int);
void ixp425_md_attach(device_t);
#endif /* _IXP425VAR_H_ */

2398
sys/dev/msk/if_mskreg.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,6 @@
# $FreeBSD$
KMOD= ng_deflate
SRCS= ng_deflate.c
.include <bsd.kmod.mk>

View File

@ -0,0 +1,6 @@
# $FreeBSD$
KMOD= ng_pred1
SRCS= ng_pred1.c
.include <bsd.kmod.mk>

684
sys/netgraph/ng_deflate.c Normal file
View File

@ -0,0 +1,684 @@
/*-
* Copyright (c) 2006 Alexander Motin <mav@alkar.net>
* 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 unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* $FreeBSD$
*/
/*
* Deflate PPP compression netgraph node type.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <net/zlib.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_deflate.h>
#include "opt_netgraph.h"
MALLOC_DEFINE(M_NETGRAPH_DEFLATE, "netgraph_deflate", "netgraph deflate node ");
/* DEFLATE header length */
#define DEFLATE_HDRLEN 2
#define PROT_COMPD 0x00fd
#define DEFLATE_BUF_SIZE 4096
/* Node private data */
struct ng_deflate_private {
struct ng_deflate_config cfg; /* configuration */
u_char inbuf[DEFLATE_BUF_SIZE]; /* input buffer */
u_char outbuf[DEFLATE_BUF_SIZE]; /* output buffer */
z_stream cx; /* compression context */
struct ng_deflate_stats stats; /* statistics */
ng_ID_t ctrlnode; /* path to controlling node */
uint16_t seqnum; /* sequence number */
u_char compress; /* compress/decompress flag */
};
typedef struct ng_deflate_private *priv_p;
/* Netgraph node methods */
static ng_constructor_t ng_deflate_constructor;
static ng_rcvmsg_t ng_deflate_rcvmsg;
static ng_shutdown_t ng_deflate_shutdown;
static ng_newhook_t ng_deflate_newhook;
static ng_rcvdata_t ng_deflate_rcvdata;
static ng_disconnect_t ng_deflate_disconnect;
/* Helper functions */
static void *z_alloc(void *, u_int items, u_int size);
static void z_free(void *, void *ptr);
static int ng_deflate_compress(node_p node,
struct mbuf *m, struct mbuf **resultp);
static int ng_deflate_decompress(node_p node,
struct mbuf *m, struct mbuf **resultp);
static void ng_deflate_reset_req(node_p node);
/* Parse type for struct ng_deflate_config. */
static const struct ng_parse_struct_field ng_deflate_config_type_fields[]
= NG_DEFLATE_CONFIG_INFO;
static const struct ng_parse_type ng_deflate_config_type = {
&ng_parse_struct_type,
ng_deflate_config_type_fields
};
/* Parse type for struct ng_deflate_stat. */
static const struct ng_parse_struct_field ng_deflate_stats_type_fields[]
= NG_DEFLATE_STATS_INFO;
static const struct ng_parse_type ng_deflate_stat_type = {
&ng_parse_struct_type,
ng_deflate_stats_type_fields
};
/* List of commands and how to convert arguments to/from ASCII. */
static const struct ng_cmdlist ng_deflate_cmds[] = {
{
NGM_DEFLATE_COOKIE,
NGM_DEFLATE_CONFIG,
"config",
&ng_deflate_config_type,
NULL
},
{
NGM_DEFLATE_COOKIE,
NGM_DEFLATE_RESETREQ,
"resetreq",
NULL,
NULL
},
{
NGM_DEFLATE_COOKIE,
NGM_DEFLATE_GET_STATS,
"getstats",
NULL,
&ng_deflate_stat_type
},
{
NGM_DEFLATE_COOKIE,
NGM_DEFLATE_CLR_STATS,
"clrstats",
NULL,
NULL
},
{
NGM_DEFLATE_COOKIE,
NGM_DEFLATE_GETCLR_STATS,
"getclrstats",
NULL,
&ng_deflate_stat_type
},
{ 0 }
};
/* Node type descriptor */
static struct ng_type ng_deflate_typestruct = {
.version = NG_ABI_VERSION,
.name = NG_DEFLATE_NODE_TYPE,
.constructor = ng_deflate_constructor,
.rcvmsg = ng_deflate_rcvmsg,
.shutdown = ng_deflate_shutdown,
.newhook = ng_deflate_newhook,
.rcvdata = ng_deflate_rcvdata,
.disconnect = ng_deflate_disconnect,
.cmdlist = ng_deflate_cmds,
};
NETGRAPH_INIT(deflate, &ng_deflate_typestruct);
/* Depend on separate zlib module. */
MODULE_DEPEND(ng_deflate, zlib, 1, 1, 1);
#define ERROUT(x) do { error = (x); goto done; } while (0)
/************************************************************************
NETGRAPH NODE STUFF
************************************************************************/
/*
* Node type constructor
*/
static int
ng_deflate_constructor(node_p node)
{
priv_p priv;
/* Allocate private structure. */
priv = malloc(sizeof(*priv), M_NETGRAPH_DEFLATE, M_WAITOK | M_ZERO);
NG_NODE_SET_PRIVATE(node, priv);
/* This node is not thread safe. */
NG_NODE_FORCE_WRITER(node);
/* Done */
return (0);
}
/*
* Give our OK for a hook to be added.
*/
static int
ng_deflate_newhook(node_p node, hook_p hook, const char *name)
{
const priv_p priv = NG_NODE_PRIVATE(node);
if (NG_NODE_NUMHOOKS(node) > 0)
return (EINVAL);
if (strcmp(name, NG_DEFLATE_HOOK_COMP) == 0)
priv->compress = 1;
else if (strcmp(name, NG_DEFLATE_HOOK_DECOMP) == 0)
priv->compress = 0;
else
return (EINVAL);
return (0);
}
/*
* Receive a control message
*/
static int
ng_deflate_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
NGI_GET_MSG(item, msg);
if (msg->header.typecookie != NGM_DEFLATE_COOKIE)
ERROUT(EINVAL);
switch (msg->header.cmd) {
case NGM_DEFLATE_CONFIG:
{
struct ng_deflate_config *const cfg
= (struct ng_deflate_config *)msg->data;
/* Check configuration. */
if (msg->header.arglen != sizeof(*cfg))
ERROUT(EINVAL);
if (cfg->enable) {
if (cfg->windowBits < 8 || cfg->windowBits > 15)
ERROUT(EINVAL);
} else
cfg->windowBits = 0;
/* Clear previous state. */
if (priv->cfg.enable) {
if (priv->compress)
deflateEnd(&priv->cx);
else
inflateEnd(&priv->cx);
priv->cfg.enable = 0;
}
/* Configuration is OK, reset to it. */
priv->cfg = *cfg;
if (priv->cfg.enable) {
priv->cx.next_in = NULL;
priv->cx.zalloc = z_alloc;
priv->cx.zfree = z_free;
int res;
if (priv->compress) {
if ((res = deflateInit2(&priv->cx,
Z_DEFAULT_COMPRESSION, Z_DEFLATED,
-cfg->windowBits, 8,
Z_DEFAULT_STRATEGY)) != Z_OK) {
log(LOG_NOTICE,
"deflateInit2: error %d, %s\n",
res, priv->cx.msg);
priv->cfg.enable = 0;
ERROUT(ENOMEM);
}
} else {
if ((res = inflateInit2(&priv->cx,
-cfg->windowBits)) != Z_OK) {
log(LOG_NOTICE,
"inflateInit2: error %d, %s\n",
res, priv->cx.msg);
priv->cfg.enable = 0;
ERROUT(ENOMEM);
}
}
}
/* Initialize other state. */
priv->seqnum = 0;
/* Save return address so we can send reset-req's */
priv->ctrlnode = NGI_RETADDR(item);
break;
}
case NGM_DEFLATE_RESETREQ:
ng_deflate_reset_req(node);
break;
case NGM_DEFLATE_GET_STATS:
case NGM_DEFLATE_CLR_STATS:
case NGM_DEFLATE_GETCLR_STATS:
/* Create response if requested. */
if (msg->header.cmd != NGM_DEFLATE_CLR_STATS) {
NG_MKRESPONSE(resp, msg,
sizeof(struct ng_deflate_stats), M_NOWAIT);
if (resp == NULL)
ERROUT(ENOMEM);
bcopy(&priv->stats, resp->data,
sizeof(struct ng_deflate_stats));
}
/* Clear stats if requested. */
if (msg->header.cmd != NGM_DEFLATE_GET_STATS)
bzero(&priv->stats,
sizeof(struct ng_deflate_stats));
break;
default:
error = EINVAL;
break;
}
done:
NG_RESPOND_MSG(error, node, item, resp);
NG_FREE_MSG(msg);
return (error);
}
/*
* Receive incoming data on our hook.
*/
static int
ng_deflate_rcvdata(hook_p hook, item_p item)
{
const node_p node = NG_HOOK_NODE(hook);
const priv_p priv = NG_NODE_PRIVATE(node);
struct mbuf *m, *out;
int error;
if (!priv->cfg.enable) {
NG_FREE_ITEM(item);
return (ENXIO);
}
NGI_GET_M(item, m);
/* Compress */
if (priv->compress) {
if ((error = ng_deflate_compress(node, m, &out)) != 0) {
NG_FREE_ITEM(item);
log(LOG_NOTICE, "%s: error: %d\n", __func__, error);
return (error);
}
} else { /* Decompress */
if ((error = ng_deflate_decompress(node, m, &out)) != 0) {
NG_FREE_ITEM(item);
log(LOG_NOTICE, "%s: error: %d\n", __func__, error);
if (priv->ctrlnode != 0) {
struct ng_mesg *msg;
/* Need to send a reset-request. */
NG_MKMESSAGE(msg, NGM_DEFLATE_COOKIE,
NGM_DEFLATE_RESETREQ, 0, M_NOWAIT);
if (msg == NULL)
return (error);
NG_SEND_MSG_ID(error, node, msg,
priv->ctrlnode, 0);
}
return (error);
}
}
NG_FWD_NEW_DATA(error, item, hook, out);
return (error);
}
/*
* Destroy node.
*/
static int
ng_deflate_shutdown(node_p node)
{
const priv_p priv = NG_NODE_PRIVATE(node);
/* Take down netgraph node. */
if (priv->cfg.enable) {
if (priv->compress)
deflateEnd(&priv->cx);
else
inflateEnd(&priv->cx);
}
free(priv, M_NETGRAPH_DEFLATE);
NG_NODE_SET_PRIVATE(node, NULL);
NG_NODE_UNREF(node); /* let the node escape */
return (0);
}
/*
* Hook disconnection
*/
static int
ng_deflate_disconnect(hook_p hook)
{
const node_p node = NG_HOOK_NODE(hook);
const priv_p priv = NG_NODE_PRIVATE(node);
if (priv->cfg.enable) {
if (priv->compress)
deflateEnd(&priv->cx);
else
inflateEnd(&priv->cx);
priv->cfg.enable = 0;
}
/* Go away if no longer connected. */
if ((NG_NODE_NUMHOOKS(node) == 0) && NG_NODE_IS_VALID(node))
ng_rmnode_self(node);
return (0);
}
/************************************************************************
HELPER STUFF
************************************************************************/
/*
* Space allocation and freeing routines for use by zlib routines.
*/
static void *
z_alloc(void *notused, u_int items, u_int size)
{
return (malloc(items * size, M_NETGRAPH_DEFLATE, M_NOWAIT));
}
static void
z_free(void *notused, void *ptr)
{
free(ptr, M_NETGRAPH_DEFLATE);
}
/*
* Compress/encrypt a packet and put the result in a new mbuf at *resultp.
* The original mbuf is not free'd.
*/
static int
ng_deflate_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
{
const priv_p priv = NG_NODE_PRIVATE(node);
int outlen, inlen;
int rtn;
/* Initialize. */
*resultp = NULL;
inlen = m->m_pkthdr.len;
priv->stats.FramesPlain++;
priv->stats.InOctets+=inlen;
if (inlen > DEFLATE_BUF_SIZE) {
priv->stats.Errors++;
NG_FREE_M(m);
return (ENOMEM);
}
/* Work with contiguous regions of memory. */
m_copydata(m, 0, inlen, (caddr_t)priv->inbuf);
outlen = DEFLATE_BUF_SIZE;
/* Compress "inbuf" into "outbuf". */
/* Prepare to compress. */
if (priv->inbuf[0] != 0) {
priv->cx.next_in = priv->inbuf;
priv->cx.avail_in = inlen;
} else {
priv->cx.next_in = priv->inbuf + 1; /* compress protocol */
priv->cx.avail_in = inlen - 1;
}
priv->cx.next_out = priv->outbuf + 2 + DEFLATE_HDRLEN;
priv->cx.avail_out = outlen - 2 - DEFLATE_HDRLEN;
/* Compress. */
rtn = deflate(&priv->cx, Z_PACKET_FLUSH);
/* Check return value. */
if (rtn != Z_OK) {
priv->stats.Errors++;
log(LOG_NOTICE, "ng_deflate: compression error: %d (%s)\n",
rtn, priv->cx.msg);
NG_FREE_M(m);
return (EINVAL);
}
/* Calculate resulting size. */
outlen -= priv->cx.avail_out;
/* If we can't compress this packet, send it as-is. */
if (outlen > inlen) {
/* Return original packet uncompressed. */
*resultp = m;
priv->stats.FramesUncomp++;
priv->stats.OutOctets+=inlen;
} else {
NG_FREE_M(m);
/* Install header. */
((u_int16_t *)priv->outbuf)[0] = htons(PROT_COMPD);
((u_int16_t *)priv->outbuf)[1] = htons(priv->seqnum);
/* Return packet in an mbuf. */
*resultp = m_devget((caddr_t)priv->outbuf, outlen, 0, NULL,
NULL);
if (*resultp == NULL) {
priv->stats.Errors++;
return (ENOMEM);
};
priv->stats.FramesComp++;
priv->stats.OutOctets+=outlen;
}
/* Update sequence number. */
priv->seqnum++;
return (0);
}
/*
* Decompress/decrypt packet and put the result in a new mbuf at *resultp.
* The original mbuf is not free'd.
*/
static int
ng_deflate_decompress(node_p node, struct mbuf *m, struct mbuf **resultp)
{
const priv_p priv = NG_NODE_PRIVATE(node);
int outlen, inlen;
int rtn;
uint16_t proto;
int offset;
uint16_t rseqnum;
/* Initialize. */
*resultp = NULL;
inlen = m->m_pkthdr.len;
if (inlen > DEFLATE_BUF_SIZE) {
priv->stats.Errors++;
NG_FREE_M(m);
priv->seqnum = 0;
return (ENOMEM);
}
/* Work with contiguous regions of memory. */
m_copydata(m, 0, inlen, (caddr_t)priv->inbuf);
/* Separate proto. */
if ((priv->inbuf[0] & 0x01) != 0) {
proto = priv->inbuf[0];
offset = 1;
} else {
proto = ntohs(((uint16_t *)priv->inbuf)[0]);
offset = 2;
}
priv->stats.InOctets += inlen;
/* Packet is compressed, so decompress. */
if (proto == PROT_COMPD) {
priv->stats.FramesComp++;
/* Check sequence number. */
rseqnum = ntohs(((uint16_t *)(priv->inbuf + offset))[0]);
offset += 2;
if (rseqnum != priv->seqnum) {
priv->stats.Errors++;
log(LOG_NOTICE, "ng_deflate: wrong sequence: %u "
"instead of %u\n", rseqnum, priv->seqnum);
NG_FREE_M(m);
priv->seqnum = 0;
return (EPIPE);
}
outlen = DEFLATE_BUF_SIZE;
/* Decompress "inbuf" into "outbuf". */
/* Prepare to decompress. */
priv->cx.next_in = priv->inbuf + offset;
priv->cx.avail_in = inlen - offset;
/* Reserve space for protocol decompression. */
priv->cx.next_out = priv->outbuf + 1;
priv->cx.avail_out = outlen - 1;
/* Decompress. */
rtn = inflate(&priv->cx, Z_PACKET_FLUSH);
/* Check return value. */
if (rtn != Z_OK && rtn != Z_STREAM_END) {
priv->stats.Errors++;
NG_FREE_M(m);
priv->seqnum = 0;
log(LOG_NOTICE, "%s: decompression error: %d (%s)\n",
__func__, rtn, priv->cx.msg);
switch (rtn) {
case Z_MEM_ERROR:
return (ENOMEM);
case Z_DATA_ERROR:
return (EIO);
default:
return (EINVAL);
}
}
/* Calculate resulting size. */
outlen -= priv->cx.avail_out;
NG_FREE_M(m);
/* Decompress protocol. */
if ((priv->outbuf[1] & 0x01) != 0) {
priv->outbuf[0] = 0;
/* Return packet in an mbuf. */
*resultp = m_devget((caddr_t)priv->outbuf, outlen, 0,
NULL, NULL);
} else {
outlen--;
/* Return packet in an mbuf. */
*resultp = m_devget((caddr_t)(priv->outbuf + 1),
outlen, 0, NULL, NULL);
}
if (*resultp == NULL) {
priv->stats.Errors++;
priv->seqnum = 0;
return (ENOMEM);
};
priv->stats.FramesPlain++;
priv->stats.OutOctets+=outlen;
} else { /* Packet is not compressed, just update dictionary. */
priv->stats.FramesUncomp++;
if (priv->inbuf[0] == 0) {
priv->cx.next_in = priv->inbuf + 1; /* compress protocol */
priv->cx.avail_in = inlen - 1;
} else {
priv->cx.next_in = priv->inbuf;
priv->cx.avail_in = inlen;
}
rtn = inflateIncomp(&priv->cx);
/* Check return value */
if (rtn != Z_OK) {
priv->stats.Errors++;
log(LOG_NOTICE, "%s: inflateIncomp error: %d (%s)\n",
__func__, rtn, priv->cx.msg);
NG_FREE_M(m);
priv->seqnum = 0;
return (EINVAL);
}
*resultp = m;
priv->stats.FramesPlain++;
priv->stats.OutOctets += inlen;
}
/* Update sequence number. */
priv->seqnum++;
return (0);
}
/*
* The peer has sent us a CCP ResetRequest, so reset our transmit state.
*/
static void
ng_deflate_reset_req(node_p node)
{
const priv_p priv = NG_NODE_PRIVATE(node);
priv->seqnum = 0;
if (priv->cfg.enable) {
if (priv->compress)
deflateReset(&priv->cx);
else
inflateReset(&priv->cx);
}
}

85
sys/netgraph/ng_deflate.h Normal file
View File

@ -0,0 +1,85 @@
/*-
* Copyright (c) 2006 Alexander Motin <mav@alkar.net>
* 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 unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* $FreeBSD$
*/
#ifndef _NETGRAPH_NG_DEFLATE_H_
#define _NETGRAPH_NG_DEFLATE_H_
/* Node type name and magic cookie */
#define NG_DEFLATE_NODE_TYPE "deflate"
#define NGM_DEFLATE_COOKIE 1166642656
/* Hook names */
#define NG_DEFLATE_HOOK_COMP "comp" /* compression hook */
#define NG_DEFLATE_HOOK_DECOMP "decomp" /* decompression hook */
/* Config struct */
struct ng_deflate_config {
u_char enable; /* node enabled */
u_char windowBits; /* log2(Window size) */
};
/* Keep this in sync with the above structure definition. */
#define NG_DEFLATE_CONFIG_INFO { \
{ "enable", &ng_parse_uint8_type }, \
{ "windowBits", &ng_parse_uint8_type }, \
{ NULL } \
}
/* Statistics structure for one direction. */
struct ng_deflate_stats {
uint64_t FramesPlain;
uint64_t FramesComp;
uint64_t FramesUncomp;
uint64_t InOctets;
uint64_t OutOctets;
uint64_t Errors;
};
/* Keep this in sync with the above structure definition. */
#define NG_DEFLATE_STATS_INFO { \
{ "FramesPlain",&ng_parse_uint64_type }, \
{ "FramesComp", &ng_parse_uint64_type }, \
{ "FramesUncomp", &ng_parse_uint64_type }, \
{ "InOctets", &ng_parse_uint64_type }, \
{ "OutOctets", &ng_parse_uint64_type }, \
{ "Errors", &ng_parse_uint64_type }, \
{ NULL } \
}
/* Netgraph commands */
enum {
NGM_DEFLATE_CONFIG = 1,
NGM_DEFLATE_RESETREQ, /* sent either way! */
NGM_DEFLATE_GET_STATS,
NGM_DEFLATE_CLR_STATS,
NGM_DEFLATE_GETCLR_STATS,
};
#endif /* _NETGRAPH_NG_DEFLATE_H_ */

698
sys/netgraph/ng_pred1.c Normal file
View File

@ -0,0 +1,698 @@
/*-
* Copyright (c) 2006 Alexander Motin <mav@alkar.net>
* 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 unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* $FreeBSD$
*/
/*
* Predictor-1 PPP compression netgraph node type.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_pred1.h>
#include "opt_netgraph.h"
MALLOC_DEFINE(M_NETGRAPH_PRED1, "netgraph_pred1", "netgraph pred1 node ");
/* PRED1 header length */
#define PRED1_HDRLEN 2
#define PRED1_TABLE_SIZE 0x10000
#define PRED1_BUF_SIZE 4096
#define PPP_INITFCS 0xffff /* Initial FCS value */
#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */
/*
* The following hash code is the heart of the algorithm:
* it builds a sliding hash sum of the previous 3-and-a-bit
* characters which will be used to index the guess table.
* A better hash function would result in additional compression,
* at the expense of time.
*/
#define HASH(x) priv->Hash = (priv->Hash << 4) ^ (x)
/* Node private data */
struct ng_pred1_private {
struct ng_pred1_config cfg; /* configuration */
u_char GuessTable[PRED1_TABLE_SIZE]; /* dictionary */
u_char inbuf[PRED1_BUF_SIZE]; /* input buffer */
u_char outbuf[PRED1_BUF_SIZE]; /* output buffer */
struct ng_pred1_stats stats; /* statistics */
uint16_t Hash;
ng_ID_t ctrlnode; /* path to controlling node */
uint16_t seqnum; /* sequence number */
u_char compress; /* compress/decompress flag */
};
typedef struct ng_pred1_private *priv_p;
/* Netgraph node methods */
static ng_constructor_t ng_pred1_constructor;
static ng_rcvmsg_t ng_pred1_rcvmsg;
static ng_shutdown_t ng_pred1_shutdown;
static ng_newhook_t ng_pred1_newhook;
static ng_rcvdata_t ng_pred1_rcvdata;
static ng_disconnect_t ng_pred1_disconnect;
/* Helper functions */
static int ng_pred1_compress(node_p node, struct mbuf *m,
struct mbuf **resultp);
static int ng_pred1_decompress(node_p node, struct mbuf *m,
struct mbuf **resultp);
static void Pred1Init(node_p node);
static int Pred1Compress(node_p node, u_char *source, u_char *dest,
int len);
static int Pred1Decompress(node_p node, u_char *source, u_char *dest,
int slen, int dlen);
static void Pred1SyncTable(node_p node, u_char *source, int len);
static uint16_t Crc16(uint16_t fcs, u_char *cp, int len);
static const uint16_t Crc16Table[];
/* Parse type for struct ng_pred1_config. */
static const struct ng_parse_struct_field ng_pred1_config_type_fields[]
= NG_PRED1_CONFIG_INFO;
static const struct ng_parse_type ng_pred1_config_type = {
&ng_parse_struct_type,
ng_pred1_config_type_fields
};
/* Parse type for struct ng_pred1_stat. */
static const struct ng_parse_struct_field ng_pred1_stats_type_fields[]
= NG_PRED1_STATS_INFO;
static const struct ng_parse_type ng_pred1_stat_type = {
&ng_parse_struct_type,
ng_pred1_stats_type_fields
};
/* List of commands and how to convert arguments to/from ASCII. */
static const struct ng_cmdlist ng_pred1_cmds[] = {
{
NGM_PRED1_COOKIE,
NGM_PRED1_CONFIG,
"config",
&ng_pred1_config_type,
NULL
},
{
NGM_PRED1_COOKIE,
NGM_PRED1_RESETREQ,
"resetreq",
NULL,
NULL
},
{
NGM_PRED1_COOKIE,
NGM_PRED1_GET_STATS,
"getstats",
NULL,
&ng_pred1_stat_type
},
{
NGM_PRED1_COOKIE,
NGM_PRED1_CLR_STATS,
"clrstats",
NULL,
NULL
},
{
NGM_PRED1_COOKIE,
NGM_PRED1_GETCLR_STATS,
"getclrstats",
NULL,
&ng_pred1_stat_type
},
{ 0 }
};
/* Node type descriptor */
static struct ng_type ng_pred1_typestruct = {
.version = NG_ABI_VERSION,
.name = NG_PRED1_NODE_TYPE,
.constructor = ng_pred1_constructor,
.rcvmsg = ng_pred1_rcvmsg,
.shutdown = ng_pred1_shutdown,
.newhook = ng_pred1_newhook,
.rcvdata = ng_pred1_rcvdata,
.disconnect = ng_pred1_disconnect,
.cmdlist = ng_pred1_cmds,
};
NETGRAPH_INIT(pred1, &ng_pred1_typestruct);
#define ERROUT(x) do { error = (x); goto done; } while (0)
/************************************************************************
NETGRAPH NODE STUFF
************************************************************************/
/*
* Node type constructor
*/
static int
ng_pred1_constructor(node_p node)
{
priv_p priv;
/* Allocate private structure. */
priv = malloc(sizeof(*priv), M_NETGRAPH_PRED1, M_WAITOK | M_ZERO);
NG_NODE_SET_PRIVATE(node, priv);
/* This node is not thread safe. */
NG_NODE_FORCE_WRITER(node);
/* Done */
return (0);
}
/*
* Give our OK for a hook to be added.
*/
static int
ng_pred1_newhook(node_p node, hook_p hook, const char *name)
{
const priv_p priv = NG_NODE_PRIVATE(node);
if (NG_NODE_NUMHOOKS(node) > 0)
return (EINVAL);
if (strcmp(name, NG_PRED1_HOOK_COMP) == 0)
priv->compress = 1;
else if (strcmp(name, NG_PRED1_HOOK_DECOMP) == 0)
priv->compress = 0;
else
return (EINVAL);
return (0);
}
/*
* Receive a control message.
*/
static int
ng_pred1_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
NGI_GET_MSG(item, msg);
if (msg->header.typecookie != NGM_PRED1_COOKIE)
ERROUT(EINVAL);
switch (msg->header.cmd) {
case NGM_PRED1_CONFIG:
{
struct ng_pred1_config *const cfg =
(struct ng_pred1_config *)msg->data;
/* Check configuration. */
if (msg->header.arglen != sizeof(*cfg))
ERROUT(EINVAL);
/* Configuration is OK, reset to it. */
priv->cfg = *cfg;
/* Save return address so we can send reset-req's. */
priv->ctrlnode = NGI_RETADDR(item);
/* Clear our state. */
Pred1Init(node);
break;
}
case NGM_PRED1_RESETREQ:
Pred1Init(node);
break;
case NGM_PRED1_GET_STATS:
case NGM_PRED1_CLR_STATS:
case NGM_PRED1_GETCLR_STATS:
{
/* Create response. */
if (msg->header.cmd != NGM_PRED1_CLR_STATS) {
NG_MKRESPONSE(resp, msg,
sizeof(struct ng_pred1_stats), M_NOWAIT);
if (resp == NULL)
ERROUT(ENOMEM);
bcopy(&priv->stats, resp->data,
sizeof(struct ng_pred1_stats));
}
if (msg->header.cmd != NGM_PRED1_GET_STATS)
bzero(&priv->stats, sizeof(struct ng_pred1_stats));
break;
}
default:
error = EINVAL;
break;
}
done:
NG_RESPOND_MSG(error, node, item, resp);
NG_FREE_MSG(msg);
return (error);
}
/*
* Receive incoming data on our hook.
*/
static int
ng_pred1_rcvdata(hook_p hook, item_p item)
{
const node_p node = NG_HOOK_NODE(hook);
const priv_p priv = NG_NODE_PRIVATE(node);
struct mbuf *m, *out;
int error;
if (!priv->cfg.enable) {
NG_FREE_ITEM(item);
return (ENXIO);
}
NGI_GET_M(item, m);
/* Compress. */
if (priv->compress) {
if ((error = ng_pred1_compress(node, m, &out)) != 0) {
NG_FREE_ITEM(item);
log(LOG_NOTICE, "%s: error: %d\n", __func__, error);
return (error);
}
} else { /* Decompress. */
if ((error = ng_pred1_decompress(node, m, &out)) != 0) {
NG_FREE_ITEM(item);
log(LOG_NOTICE, "%s: error: %d\n", __func__, error);
if (priv->ctrlnode != 0) {
struct ng_mesg *msg;
/* Need to send a reset-request. */
NG_MKMESSAGE(msg, NGM_PRED1_COOKIE,
NGM_PRED1_RESETREQ, 0, M_NOWAIT);
if (msg == NULL)
return (error);
NG_SEND_MSG_ID(error, node, msg,
priv->ctrlnode, 0);
}
return (error);
}
}
NG_FWD_NEW_DATA(error, item, hook, out);
return (error);
}
/*
* Destroy node.
*/
static int
ng_pred1_shutdown(node_p node)
{
const priv_p priv = NG_NODE_PRIVATE(node);
free(priv, M_NETGRAPH_PRED1);
NG_NODE_SET_PRIVATE(node, NULL);
NG_NODE_UNREF(node); /* Let the node escape. */
return (0);
}
/*
* Hook disconnection
*/
static int
ng_pred1_disconnect(hook_p hook)
{
const node_p node = NG_HOOK_NODE(hook);
Pred1Init(node);
/* Go away if no longer connected. */
if ((NG_NODE_NUMHOOKS(node) == 0) && NG_NODE_IS_VALID(node))
ng_rmnode_self(node);
return (0);
}
/************************************************************************
HELPER STUFF
************************************************************************/
/*
* Compress/encrypt a packet and put the result in a new mbuf at *resultp.
* The original mbuf is not free'd.
*/
static int
ng_pred1_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
{
const priv_p priv = NG_NODE_PRIVATE(node);
int outlen, inlen;
u_char *out;
uint16_t fcs, lenn;
int len;
/* Initialize. */
*resultp = NULL;
inlen = m->m_pkthdr.len;
priv->stats.FramesPlain++;
priv->stats.InOctets += inlen;
/* Reserve space for expansion. */
if (inlen > (PRED1_BUF_SIZE*8/9 + 1 + 4)) {
priv->stats.Errors++;
NG_FREE_M(m);
return (ENOMEM);
}
/* Work with contiguous regions of memory. */
m_copydata(m, 0, inlen, (caddr_t)(priv->inbuf + 2));
NG_FREE_M(m);
lenn = htons(inlen & 0x7FFF);
/* Compute FCS. */
fcs = Crc16(PPP_INITFCS, (u_char *)&lenn, 2);
fcs = Crc16(fcs, priv->inbuf + 2, inlen);
fcs = ~fcs;
/* Compress data. */
len = Pred1Compress(node, priv->inbuf + 2, priv->outbuf + 2, inlen);
/* What happened? */
if (len < inlen) {
out = priv->outbuf;
outlen = 2 + len;
*(uint16_t *)out = lenn;
*out |= 0x80;
priv->stats.FramesComp++;
} else {
out = priv->inbuf;
outlen = 2 + inlen;
*(uint16_t *)out = lenn;
priv->stats.FramesUncomp++;
}
/* Add FCS. */
(out + outlen)[0] = fcs & 0xFF;
(out + outlen)[1] = fcs >> 8;
/* Calculate resulting size. */
outlen += 2;
/* Return packet in an mbuf. */
*resultp = m_devget((caddr_t)out, outlen, 0, NULL, NULL);
if (*resultp == NULL) {
priv->stats.Errors++;
return (ENOMEM);
};
priv->stats.OutOctets += outlen;
return (0);
}
/*
* Decompress/decrypt packet and put the result in a new mbuf at *resultp.
* The original mbuf is not free'd.
*/
static int
ng_pred1_decompress(node_p node, struct mbuf *m, struct mbuf **resultp)
{
const priv_p priv = NG_NODE_PRIVATE(node);
int inlen;
uint16_t len, len1, cf, lenn;
uint16_t fcs;
/* Initialize. */
*resultp = NULL;
inlen = m->m_pkthdr.len;
if (inlen > PRED1_BUF_SIZE) {
priv->stats.Errors++;
NG_FREE_M(m);
return (ENOMEM);
}
/* Work with contiguous regions of memory. */
m_copydata(m, 0, inlen, (caddr_t)priv->inbuf);
priv->stats.InOctets += inlen;
/* Get initial length value. */
len = priv->inbuf[0] << 8;
len += priv->inbuf[1];
cf = (len & 0x8000);
len &= 0x7fff;
/* Is data compressed or not really? */
if (cf) {
NG_FREE_M(m);
priv->stats.FramesComp++;
len1 = Pred1Decompress(node, priv->inbuf + 2, priv->outbuf,
inlen - 4, PRED1_BUF_SIZE);
if (len != len1) {
/* Error is detected. Send reset request */
priv->stats.Errors++;
log(LOG_NOTICE, "ng_pred1: Comp length error (%d) "
"--> len (%d)\n", len, len1);
return (EIO);
}
/*
* CRC check on receive is defined in RFC. It is surely required
* for compressed frames to signal dictionary corruption,
* but it is actually useless for uncompressed frames because
* the same check has already done by HDLC and/or other layer.
*/
lenn = htons(len);
fcs = Crc16(PPP_INITFCS, (u_char *)&lenn, 2);
fcs = Crc16(fcs, priv->outbuf, len);
fcs = Crc16(fcs, priv->inbuf + inlen - 2, 2);
if (fcs != PPP_GOODFCS) {
priv->stats.Errors++;
log(LOG_NOTICE, "ng_pred1: Pred1: Bad CRC-16\n");
return (EIO);
}
/* Return packet in an mbuf. */
*resultp = m_devget((caddr_t)priv->outbuf, len, 0, NULL, NULL);
if (*resultp == NULL) {
priv->stats.Errors++;
return (ENOMEM);
};
} else {
priv->stats.FramesUncomp++;
if (len != (inlen - 4)) {
/* Wrong length. Send reset request */
priv->stats.Errors++;
log(LOG_NOTICE, "ng_pred1: Uncomp length error (%d) "
"--> len (%d)\n", len, inlen - 4);
NG_FREE_M(m);
return (EIO);
}
Pred1SyncTable(node, priv->inbuf + 2, len);
m_adj(m, 2); /* Strip length. */
m_adj(m, -2); /* Strip fcs. */
*resultp = m;
}
priv->stats.FramesPlain++;
priv->stats.OutOctets += len;
return (0);
}
/*
* Pred1Init()
*/
static void
Pred1Init(node_p node)
{
const priv_p priv = NG_NODE_PRIVATE(node);
priv->Hash = 0;
memset(priv->GuessTable, 0, PRED1_TABLE_SIZE);
}
/*
* Pred1Compress()
*/
static int
Pred1Compress(node_p node, u_char *source, u_char *dest, int len)
{
const priv_p priv = NG_NODE_PRIVATE(node);
int i, bitmask;
u_char flags;
u_char *flagdest, *orgdest;
orgdest = dest;
while (len) {
flagdest = dest++;
flags = 0; /* All guesses are wrong initially. */
for (bitmask = 1, i = 0; i < 8 && len; i++, bitmask <<= 1) {
if (priv->GuessTable[priv->Hash] == *source)
/* Guess was right - don't output. */
flags |= bitmask;
else {
/* Guess wrong, output char. */
priv->GuessTable[priv->Hash] = *source;
*dest++ = *source;
}
HASH(*source++);
len--;
}
*flagdest = flags;
}
return (dest - orgdest);
}
/*
* Pred1Decompress()
*
* Returns decompressed size, or -1 if we ran out of space.
*/
static int
Pred1Decompress(node_p node, u_char *source, u_char *dest, int slen, int dlen)
{
const priv_p priv = NG_NODE_PRIVATE(node);
int i, bitmask;
u_char flags, *orgdest;
orgdest = dest;
while (slen) {
flags = *source++;
slen--;
for (i = 0, bitmask = 1; i < 8; i++, bitmask <<= 1) {
if (dlen <= 0)
return(-1);
if (flags & bitmask)
/* Guess correct */
*dest = priv->GuessTable[priv->Hash];
else {
if (!slen)
/* We seem to be really done -- cabo. */
break;
/* Guess wrong. */
priv->GuessTable[priv->Hash] = *source;
/* Read from source. */
*dest = *source++;
slen--;
}
HASH(*dest++);
dlen--;
}
}
return (dest - orgdest);
}
/*
* Pred1SyncTable()
*/
static void
Pred1SyncTable(node_p node, u_char *source, int len)
{
const priv_p priv = NG_NODE_PRIVATE(node);
while (len--) {
priv->GuessTable[priv->Hash] = *source;
HASH(*source++);
}
}
/*
* Crc16()
*
* Compute the 16 bit frame check value, per RFC 1171 Appendix B,
* on an array of bytes.
*/
static uint16_t
Crc16(uint16_t crc, u_char *cp, int len)
{
while (len--)
crc = (crc >> 8) ^ Crc16Table[(crc ^ *cp++) & 0xff];
return (crc);
}
static const uint16_t Crc16Table[256] = {
/* 00 */ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
/* 08 */ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
/* 10 */ 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
/* 18 */ 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
/* 20 */ 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
/* 28 */ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
/* 30 */ 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
/* 38 */ 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
/* 40 */ 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
/* 48 */ 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
/* 50 */ 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
/* 58 */ 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
/* 60 */ 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
/* 68 */ 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
/* 70 */ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
/* 78 */ 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
/* 80 */ 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
/* 88 */ 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
/* 90 */ 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
/* 98 */ 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
/* a0 */ 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
/* a8 */ 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
/* b0 */ 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
/* b8 */ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
/* c0 */ 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
/* c8 */ 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
/* d0 */ 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
/* d8 */ 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
/* e0 */ 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
/* e8 */ 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
/* f0 */ 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
/* f8 */ 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};

83
sys/netgraph/ng_pred1.h Normal file
View File

@ -0,0 +1,83 @@
/*-
* Copyright (c) 2006 Alexander Motin <mav@alkar.net>
* 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 unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* $FreeBSD$
*/
#ifndef _NETGRAPH_NG_PRED1_H_
#define _NETGRAPH_NG_PRED1_H_
/* Node type name and magic cookie */
#define NG_PRED1_NODE_TYPE "pred1"
#define NGM_PRED1_COOKIE 1166902612
/* Hook names */
#define NG_PRED1_HOOK_COMP "comp" /* compression hook */
#define NG_PRED1_HOOK_DECOMP "decomp" /* decompression hook */
/* Config struct */
struct ng_pred1_config {
u_char enable; /* node enabled */
};
/* Keep this in sync with the above structure definition. */
#define NG_PRED1_CONFIG_INFO { \
{ "enable", &ng_parse_uint8_type }, \
{ NULL } \
}
/* Statistics structure for one direction. */
struct ng_pred1_stats {
uint64_t FramesPlain;
uint64_t FramesComp;
uint64_t FramesUncomp;
uint64_t InOctets;
uint64_t OutOctets;
uint64_t Errors;
};
/* Keep this in sync with the above structure definition. */
#define NG_PRED1_STATS_INFO { \
{ "FramesPlain",&ng_parse_uint64_type }, \
{ "FramesComp", &ng_parse_uint64_type }, \
{ "FramesUncomp", &ng_parse_uint64_type }, \
{ "InOctets", &ng_parse_uint64_type }, \
{ "OutOctets", &ng_parse_uint64_type }, \
{ "Errors", &ng_parse_uint64_type }, \
{ NULL } \
}
/* Netgraph commands */
enum {
NGM_PRED1_CONFIG = 1,
NGM_PRED1_RESETREQ, /* sent either way! */
NGM_PRED1_GET_STATS,
NGM_PRED1_CLR_STATS,
NGM_PRED1_GETCLR_STATS,
};
#endif /* _NETGRAPH_NG_PRED1_H_ */

179
usr.bin/gzip/gzexe Normal file
View File

@ -0,0 +1,179 @@
#!/bin/sh -
#
# $NetBSD: gzexe,v 1.3 2004/05/01 08:22:41 wiz Exp $
# $OpenBSD: gzexe,v 1.3 2003/08/05 18:22:17 deraadt Exp $
#
#-
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# $FreeBSD$
# The number of lines plus one in the on-the-fly decompression script
lines=19
# A simple string to recognize already compressed files
magic="# compressed by gzexe"
# Write the decompression script to stdout
header () {
# first section needs variable expansion, second not
cat <<- EOF
#!/bin/sh -
$magic
lines=$lines
EOF
cat <<- 'EOF'
prog=`/usr/bin/basename "$0"`
tmp=`/usr/bin/mktemp -d /tmp/gzexeXXXXXXXXXX` || {
/bin/echo "$prog: cannot create tmp dir"; exit 1
}
trap '/bin/rm -rf "$tmp"' 0
if /usr/bin/tail +$lines "$0" |
/usr/bin/gzip -dc > "$tmp/$prog" 2> /dev/null; then
/bin/chmod u+x "$tmp/$prog"
"$tmp/$prog" ${1+"$@"}
ret=$?
else
/bin/echo "$prog: cannot decompress $0"
ret=1
fi
exit $ret
EOF
}
# Test if a file is compressed by checking the magic line
compressed () {
test "X`sed -n 2p "$1" 2> /dev/null`" = "X$magic"
}
# Decompress a file
decompress () {
tmp=`mktemp /tmp/gzexeXXXXXXXXXX` || {
echo "$prog: cannot create tmp file"
return 1
}
if ! cp "$1" "$tmp"; then
echo "$prog: cannot copy $1 to $tmp"
rm -f "$tmp"
return 1
fi
if ! tail +$lines "$tmp" | gzip -vdc > "$1"; then
echo "$prog: cannot decompress $1"
cp "$tmp" "$1"
rm -f "$tmp"
return 1
fi
}
# Perform some sanity checks on the file
check () {
if test ! -e "$1"; then
echo "$prog: cannot compress non-existing file $1"
return 1
fi
if test ! -f "$1"; then
echo "$prog: cannot compress non-regular file $1"
return 1
fi
case `basename "$1"` in
sh | mktemp | rm | echo | tail | gzip | chmod)
echo "$prog: cannot compress $1, I depend on it"
return 1
esac
if test ! -x "$1"; then
echo "$prog: cannot compress $1, it is not executable"
return 1
fi
if test -u "$1" -o -g "$1"; then
echo "$prog: cannot compress $1, it has an s bit set"
return 1
fi
}
# Compress a file
compress () {
tmp=`mktemp /tmp/gzexeXXXXXXXXXX` || {
echo "$prog: cannot create tmp file"
return 1
}
if ! cp "$1" "$tmp"; then
echo "$prog: cannot copy $1 to $tmp"
rm -f "$tmp"
return 1
fi
if ! cp "$1" "$1"~; then
echo "$prog: cannot create backup copy $1~"
rm -f "$1"~ "$tmp"
return 1
fi
# Use cp to overwrite the existing file preserving mode and owner
# if possible. If the file is not writable, this will produce an
# error.
if header "$1" > "$tmp" && gzip -vc "$1" >> "$tmp"; then
if ! cp "$tmp" "$1"; then
echo "$prog: cannot copy $tmp to $1"
rm -f "$tmp"
return 1
fi
else
echo "$prog: cannot compress $1"
rm -f "$1"~ "$tmp"
return 1
fi
}
# Is the -d flag specified?
dflag=
# Return value
rc=0
if test "X$1" = X-d; then
dflag=1
shift
fi
prog=`basename "$0"`
USAGE="usage: $prog [-d] file ..."
if test $# -eq 0; then
echo $USAGE
exit 1
fi
while test $# -ne 0; do
if test $dflag; then
if ! compressed "$1"; then
echo "$prog: $1 is not compressed"
rc=1;
elif ! decompress "$1"; then
rc=$?
fi
else
if compressed "$1"; then
echo "$prog: $1 is already compressed"
rc=1;
elif ! check "$1" || ! compress "$1"; then
rc=$?
fi
fi
shift
done
exit $rc

73
usr.bin/gzip/gzexe.1 Normal file
View File

@ -0,0 +1,73 @@
.\" $NetBSD: gzexe.1,v 1.3 2003/12/28 12:49:41 wiz Exp $
.\" $OpenBSD: gzexe.1,v 1.1 2003/07/31 07:32:47 otto Exp $
.\"
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" $FreeBSD$
.Dd January 26, 2007
.Dt GZEXE 1
.Os
.Sh NAME
.Nm gzexe
.Nd create auto-decompressing executables
.Sh SYNOPSIS
.Nm gzexe
.Op Fl d
.Ar
.Sh DESCRIPTION
The
.Nm
utility uses
.Xr gzip 1
to compress executables, producing executables that decompress on-the-fly
when executed.
This saves disk space, at the cost of slower execution times.
The original executables are saved by copying each of them to a file with
the same name with a
.Sq ~
suffix appended.
After verifying that the compressed executables work as expected, the backup
files can be removed.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl d
Decompress executables previously compressed by
.Nm .
.El
.Pp
The
.Nm
program refuses to compress non-regular or non-executable files,
files with a setuid or setgid bit set, files that are already
compressed using
.Nm
or programs it needs to perform on-the-fly decompression:
.Xr sh 1 ,
.Xr mktemp 1 ,
.Xr rm 1 ,
.Xr echo 1 ,
.Xr tail 1 ,
.Xr gzip 1 ,
and
.Xr chmod 1 .
.Sh SEE ALSO
.Xr gzip 1
.Sh CAVEATS
The
.Nm
utility replaces files by overwriting them with the generated
compressed executable.
To be able to do this, it is required that the original files are writable.

202
usr.bin/gzip/gzip.1 Normal file
View File

@ -0,0 +1,202 @@
.\" $NetBSD: gzip.1,v 1.18 2005/09/30 13:46:56 wiz Exp $
.\"
.\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
.\" 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. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. 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.
.\"
.\" $FreeBSD$
.Dd January 26, 2007
.Dt GZIP 1
.Os
.Sh NAME
.Nm gzip
.Nd compression/decompression tool using Lempel-Ziv coding (LZ77)
.Sh SYNOPSIS
.Nm
.Op Fl cdfhLlNnqrtVv
.Op Fl S Ar suffix
.Ar file
.Oo
.Ar file Oo ...
.Oc
.Oc
.Nm gunzip
.Op Fl cfhLNqrtVv
.Op Fl S Ar suffix
.Ar file
.Oo
.Ar file Oo ...
.Oc
.Oc
.Nm zcat
.Op Fl fhV
.Ar file
.Oo
.Ar file Oo ...
.Oc
.Oc
.Sh DESCRIPTION
The
.Nm
program compresses and decompresses files using Lempel-Ziv coding
(LZ77).
If no
.Ar files
are specified,
.Nm
will compress from standard input, or decompress to standard output.
When in compression mode, each
.Ar file
will be replaced with another file with the suffix, set by the
.Fl S Ar suffix
option, added, if possible.
In decompression mode, each
.Ar file
will be checked for existence, as will the file with the suffix
added.
.Pp
If invoked as
.Nm gunzip
then the
.Fl d
option is enabled.
If invoked as
.Nm zcat
or
.Nm gzcat
then both the
.Fl c
and
.Fl d
options are enabled.
.Pp
This version of
.Nm
is also capable of decompressing files compressed using
.Xr compress 1
or
.Xr bzip2 1 .
.Sh OPTIONS
The following options are available:
.Bl -tag -width XXrXXXrecursiveX
.It Fl 1 , -fast
.It Fl 2 , 3 , 4 , 5 , 6 , 7 , 8
.It Fl 9 , -best
These options change the compression level used, with the
.Fl 1
option being the fastest, with less compression, and the
.Fl 9
option being the slowest, with optimal compression.
The default compression level is 6.
.It Fl c , -stdout , -to-stdout
This option specifies that output will go to the standard output
stream, leaving files intact.
.It Fl d , -decompress , -uncompress
This option selects decompression rather than compression.
.It Fl f , -force
This option turns on force mode.
This allows files with multiple links, overwriting of pre-existing
files, reading from or writing to a terminal, and when combined
with the
.Fl c
option, allowing non-compressed data to pass through unchanged.
.It Fl h , -help
This option prints a usage summary and exits.
.It Fl L , -license
This option prints
.Nm
license.
.It Fl l , -list
This option displays information about the file's compressed and
uncompressed size, ratio, uncompressed name.
With the
.Fl v
option, it also displays the compression method, CRC, date and time
embedded in the file.
.It Fl N , -name
This option causes the stored filename in the input file to be used
as the output file.
.It Fl n , -no-name
This option stops the filename from being stored in the output
file.
.It Fl q , -quiet
With this option, no warnings or errors are printed.
.It Fl r , -recursive
This option is used to
.Nm
the files in a directory tree individually, using the
.Xr fts 3
library.
.It Fl S Ar suffix , Fl -suffix Ar suffix
This option changes the default suffix from .gz to
.Ar suffix .
.It Fl t , -test
This option will test compressed files for integrity.
.It Fl V , -version
This option prints the version of the
.Nm
program.
.It Fl v , -verbose
This option turns on verbose mode, which prints the compression
ratio for each file compressed.
.El
.Sh ENVIRONMENT
If the environment variable
.Ev GZIP
is set, it is parsed as a white-space separated list of options
handled before any options on the command line.
Options on the command line will override anything in
.Ev GZIP .
.Sh SEE ALSO
.Xr bzip2 1 ,
.Xr compress 1 ,
.Xr fts 3 ,
.Xr zlib 3
.Sh HISTORY
The
.Nm
program was originally written by Jean-loup Gailly, licensed under
the GNU Public Licence.
Matthew R. Green wrote a simple front end for
.Nx 1.3
distribution media, based on the freely re-distributable zlib library.
It was enhanced to be mostly feature-compatible with the original
GNU
.Nm
program for
.Nx 2.0 .
.Pp
This implementation of
.Nm
was ported based on the
.Nx
.Nm
20060927, and first appeared in
.Fx 7.0 .
.Sh AUTHORS
This implementation of
.Nm
was written by
.An Matthew R. Green Aq mrg@eterna.com.au .

128
usr.bin/gzip/unbzip2.c Normal file
View File

@ -0,0 +1,128 @@
/* $NetBSD: unbzip2.c,v 1.10 2006/10/03 08:20:03 simonb Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Simon Burge.
*
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*
* $FreeBSD$
*/
/* This file is #included by gzip.c */
static off_t
unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
{
int ret, end_of_file;
off_t bytes_out = 0;
bz_stream bzs;
static char *inbuf, *outbuf;
if (inbuf == NULL)
inbuf = malloc(BUFLEN);
if (outbuf == NULL)
outbuf = malloc(BUFLEN);
if (inbuf == NULL || outbuf == NULL)
maybe_err("malloc");
bzs.bzalloc = NULL;
bzs.bzfree = NULL;
bzs.opaque = NULL;
end_of_file = 0;
ret = BZ2_bzDecompressInit(&bzs, 0, 0);
if (ret != BZ_OK)
maybe_errx("bzip2 init");
/* Prepend. */
bzs.avail_in = prelen;
bzs.next_in = pre;
if (bytes_in)
*bytes_in = prelen;
while (ret >= BZ_OK && ret != BZ_STREAM_END) {
if (bzs.avail_in == 0 && !end_of_file) {
ssize_t n;
n = read(in, inbuf, BUFLEN);
if (n < 0)
maybe_err("read");
if (n == 0)
end_of_file = 1;
bzs.next_in = inbuf;
bzs.avail_in = n;
if (bytes_in)
*bytes_in += n;
}
bzs.next_out = outbuf;
bzs.avail_out = BUFLEN;
ret = BZ2_bzDecompress(&bzs);
switch (ret) {
case BZ_STREAM_END:
case BZ_OK:
if (ret == BZ_OK && end_of_file)
maybe_err("read");
if (!tflag) {
ssize_t n;
n = write(out, outbuf, BUFLEN - bzs.avail_out);
if (n < 0)
maybe_err("write");
bytes_out += n;
}
break;
case BZ_DATA_ERROR:
maybe_warnx("bzip2 data integrity error");
break;
case BZ_DATA_ERROR_MAGIC:
maybe_warnx("bzip2 magic number error");
break;
case BZ_MEM_ERROR:
maybe_warnx("bzip2 out of memory");
break;
}
}
if (ret != BZ_STREAM_END || BZ2_bzDecompressEnd(&bzs) != BZ_OK)
return (-1);
return (bytes_out);
}

111
usr.bin/gzip/zdiff Normal file
View File

@ -0,0 +1,111 @@
#!/bin/sh -
#
# $NetBSD: zdiff,v 1.3 2004/03/29 10:01:00 wiz Exp $
# $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
#
#-
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Sponsored in part by the Defense Advanced Research Projects
# Agency (DARPA) and Air Force Research Laboratory, Air Force
# Materiel Command, USAF, under agreement number F39502-99-1-0512.
#
# $FreeBSD$
# Set $prog based on $0
case $0 in
*cmp) prog=cmp
;;
*) prog=diff
;;
esac
USAGE="usage: z$prog [options] file1 [file2]"
# Pull out any command line flags so we can pass them to diff/cmp
# XXX - assumes there is no optarg
flags=
while test $# -ne 0; do
case "$1" in
--)
shift
break
;;
-*)
flags="$flags $1"
shift
;;
*)
break
;;
esac
done
if [ $# -eq 1 ]; then
# One file given, compare compressed to uncompressed
files="$1"
case "$1" in
*[._-][Zz])
files="${1%??}"
;;
*[._-]gz)
files="${1%???}"
;;
*.t[ag]z)
files="${1%??}"ar
;;
*) echo "z$prog: unknown suffix" 1>&2
exit 1
esac
gzip -cdfq "$1" | $prog $flags - "$files"
status=$?
elif [ $# -eq 2 ]; then
# Two files given, compare the two uncompressing as needed
case "$1" in
*[._-][Zz]|*[._-]gz|*.t[ag]z)
files=-
filt="gzip -cdfq $1"
;;
*)
files="$1"
;;
esac
case "$2" in
*[._-][Zz]|*[._-]gz|*.t[ag]z)
if [ "$files" = "-" ]; then
tmp=`mktemp -t z$prog.XXXXXXXXXX` || exit 1
trap "rm -f $tmp" 0 1 2 3 13 15
gzip -cdfq "$2" > $tmp
files="$files $tmp"
else
files="$files -"
filt="gzip -cdfq $2"
fi
;;
*)
files="$files $2"
;;
esac
if [ -n "$filt" ]; then
$filt | $prog $flags $files
else
$prog $flags $files
fi
status=$?
else
echo "$USAGE" 1>&2
exit 1
fi
exit $status

109
usr.bin/gzip/zdiff.1 Normal file
View File

@ -0,0 +1,109 @@
.\" $NetBSD: zdiff.1,v 1.3 2003/12/28 12:48:03 wiz Exp $
.\" $OpenBSD: zdiff.1,v 1.2 2003/07/13 17:39:14 millert Exp $
.\"
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" Sponsored in part by the Defense Advanced Research Projects
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\"
.\" $FreeBSD$
.Dd January 26, 2007
.Dt ZDIFF 1
.Os
.Sh NAME
.Nm zcmp ,
.Nm zdiff
.Nd compare compressed files
.Sh SYNOPSIS
.Nm zcmp
.Op Ar options
.Ar file
.Op Ar file2
.Nm zdiff
.Op Ar options
.Ar file
.Op Ar file2
.Sh DESCRIPTION
.Nm zcmp
and
.Nm zdiff
are filters that invoke
.Xr cmp 1
or
.Xr diff 1
respectively to compare compressed files.
Such files generally have a
.Dq Z
or
.Dq gz
extension (both the
.Xr compress 1
and
.Xr gzip 1
formats are supported).
Any
.Ar options
that are specified are passed to
.Xr cmp 1
or
.Xr diff 1 .
.Pp
If only
.Ar file1
is specified, it is compared against a file with the same name, but
with the extension removed.
When both
.Ar file1
or
.Ar file2
are specified, either file may be compressed.
.Sh ENVIRONMENT
.Bl -tag -width "TMPDIR"
.It Ev TMPDIR
Directory in which to place temporary files.
If unset,
.Pa /tmp
is used.
.El
.Sh FILES
.Bl -tag -width "/tmp/zdiff.XXXXXXXXXX" -compact
.It Pa /tmp/zcmp.XXXXXXXXXX
Temporary file for
.Nm zcmp .
.It Pa /tmp/zdiff.XXXXXXXXXX
Temporary file for
.Nm zdiff .
.El
.Sh SEE ALSO
.Xr cmp 1 ,
.Xr compress 1 ,
.Xr diff 1
.Sh CAVEATS
.Nm zcmp
and
.Nm zdiff
rely solely on the file extension to determine what is, or is not,
a compressed file.
Consequently, the following are not supported as arguments:
.Bl -dash
.It
directories
.It
device special files
.It
filenames indicating the standard input
.Pq Dq \-
.El

55
usr.bin/gzip/zforce Normal file
View File

@ -0,0 +1,55 @@
#!/bin/sh -
#
# $NetBSD: zforce,v 1.2 2003/12/28 12:43:43 wiz Exp $
# $OpenBSD: zforce,v 1.2 2003/08/05 18:22:17 deraadt Exp $
#
#-
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# $FreeBSD$
prog=`basename $0`
USAGE="usage: $prog file ..."
if test $# -eq 0; then
echo $USAGE
exit 1
fi
ret=0
while test $# -ne 0; do
case "$1" in
*[._-]gz)
shift
;;
*.t[ag]z)
shift
;;
*)
if file "$1" |
grep -q "gzip compressed data" 2> /dev/null
then
n="$1".gz
if mv "$1" "$n" 2> /dev/null; then
echo "$1" -- renamed to "$n"
else
ret=1
echo $prog: cannot rename "$1" to "$n"
fi
fi
shift
;;
esac
done
exit $ret

53
usr.bin/gzip/zforce.1 Normal file
View File

@ -0,0 +1,53 @@
.\" $NetBSD: zforce.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
.\" $OpenBSD: zforce.1,v 1.1 2003/07/29 11:50:09 otto Exp $
.\"
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" $FreeBSD$
.Dd January 26, 2007
.Dt ZFORCE 1
.Os
.Sh NAME
.Nm zforce
.Nd force gzip files to have a .gz suffix
.Sh SYNOPSIS
.Nm zforce
.Ar
.Sh DESCRIPTION
The
.Nm
utility renames
.Xr gzip 1
files to have a
.Sq .gz
suffix, so that
.Xr gzip 1
will not compress them twice.
This can be useful if file names were truncated during a file transfer.
Files that have an existing
.Sq .gz ,
.Sq -gz ,
.Sq _gz ,
.Sq .tgz
or
.Sq .taz
suffix, or that have not been compressed by
.Xr gzip 1 ,
are ignored.
.Sh SEE ALSO
.Xr gzip 1
.Sh CAVEATS
.Nm
overwrites existing files without warning.

75
usr.bin/gzip/zmore Normal file
View File

@ -0,0 +1,75 @@
#!/bin/sh -
#
# $NetBSD: zmore,v 1.3 2004/03/29 09:59:42 wiz Exp $
# $OpenBSD: zmore,v 1.4 2003/07/29 07:42:45 otto Exp $
#
#-
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Sponsored in part by the Defense Advanced Research Projects
# Agency (DARPA) and Air Force Research Laboratory, Air Force
# Materiel Command, USAF, under agreement number F39502-99-1-0512.
#
# $FreeBSD$
# Pull out any command line flags so we can pass them to more/less
flags=
while test $# -ne 0; do
case "$1" in
--)
shift
break
;;
-*)
flags="$flags $1"
shift
;;
*)
break
;;
esac
done
# No files means read from stdin
if [ $# -eq 0 ]; then
gzip -cdfq 2>&1 | ${PAGER-more} $flags
exit 0
fi
oterm=`stty -g 2>/dev/null`
while test $# -ne 0; do
gzip -cdfq "$1" 2>&1 | ${PAGER-more} $flags
prev="$1"
shift
if tty -s && test -n "$oterm" -a $# -gt 0; then
#echo -n "--More--(Next file: $1)"
echo -n "$prev (END) - Next: $1 "
trap "stty $oterm 2>/dev/null" 0 1 2 3 13 15
stty cbreak -echo 2>/dev/null
REPLY=`dd bs=1 count=1 2>/dev/null`
stty $oterm 2>/dev/null
trap - 0 1 2 3 13 15
echo
case "$REPLY" in
s)
shift
;;
e|q)
break
;;
esac
fi
done
exit 0

94
usr.bin/gzip/zmore.1 Normal file
View File

@ -0,0 +1,94 @@
.\" $NetBSD: zmore.1,v 1.3 2003/12/28 12:47:52 wiz Exp $
.\" $OpenBSD: zmore.1,v 1.3 2003/06/23 21:00:48 deraadt Exp $
.\"
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" Sponsored in part by the Defense Advanced Research Projects
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\"
.\" $FreeBSD$
.Dd January 26, 2007
.Dt ZMORE 1
.Os
.Sh NAME
.Nm zmore
.Nd view compressed files on a CRT
.Sh SYNOPSIS
.Nm zmore
.Op Ar flags
.Op Ar file ...
.Sh DESCRIPTION
.Nm
is a filter that allows the viewing of files compressed with Lempel-Ziv
encoding.
Such files generally have a
.Dq Z
or
.Dq gz
extension (both the
.Xr compress 1
and
.Xr gzip 1
formats are supported).
Any
.Ar flags
that are specified are passed to the user's preferred
.Ev PAGER
(which is
.Pa /usr/bin/more
by default).
.Pp
When multiple files are specified,
.Nm
will pause at the end of each file and present the following prompt to the user:
.Bd -literal -offset indent
prev_file (END) - Next: next_file
.Ed
.Pp
Where
.Sy prev_file
is the file that was just displayed and
.Sy next_file
is the next file to be displayed.
The following keys are recognized at the prompt:
.Bl -tag -width "e or q" -offset indent
.It Ic e No or Ic q
quit
.Nm zmore .
.It Ic s
skip the next file (or exit if the next file is the last).
.El
.Pp
If no files are specified,
.Nm
will read from the standard input.
In this mode
.Nm
will assume
.Xr gzip 1
style compression since there is no suffix on which to make a decision.
.Sh ENVIRONMENT
.Bl -tag -width "PAGER"
.It Ev PAGER
Program used to display files.
If unset,
.Pa /usr/bin/more
is used.
.El
.Sh SEE ALSO
.Xr compress 1 ,
.Xr less 1 ,
.Xr more 1

138
usr.bin/gzip/znew Normal file
View File

@ -0,0 +1,138 @@
#!/bin/ksh -
#
# $NetBSD: znew,v 1.2 2003/12/28 12:43:43 wiz Exp $
# $OpenBSD: znew,v 1.2 2003/08/05 18:22:17 deraadt Exp $
#
#-
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# $FreeBSD$
# Return 0 if the first arg file size is smaller than the second, 1 otherwise.
smaller () {
a=`du -k "$1" | awk '{ print $1 }'`
b=`du -k "$2" | awk '{ print $1 }'`
test $a -lt $b
}
# Check gzip integrity if the -t flag is specified
checkfile () {
if test $tflag -eq 1; then
gzip -qt < "$1"
fi
}
# Decompress a file and then gzip it
process () {
prefix="${1%.Z}"
filez="$prefix".Z
filegz="$prefix".gz
if test ! -e "$filez"; then
echo "$prog: $filez does not exist"
return 1
fi
if test ! -f "$filez"; then
echo "$prog: $filez is not a regular file"
return 1
fi
if test -e "$filegz" -a $fflag -eq 0; then
echo "$prog: $filegz already exists"
return 1
fi
tmp=`mktemp /tmp/znewXXXXXXXXXX` || {
echo "$prog: cannot create tmp file"
return 1
}
trap 'rm -f "$tmp"; exit 1' HUP INT QUIT PIPE TERM
# Do the actual work, producing a file "$tmp"
if uncompress -f -c < "$filez" | gzip -f $gzipflags -o "$tmp"; then
if test $kflag -eq 1 && smaller "$filez" "$tmp"; then
echo -n "$prog: $filez is smaller than $filegz"
echo "; keeping it"
rm -f "$tmp"
return 0
fi
if ! checkfile "$tmp"; then
echo "$prog: integrity check of $tmp failed"
rm -f "$tmp"
return 1;
fi
# Try to keep the mode of the original file
if ! cp -fp "$filez" "$filegz"; then
echo "$prog: warning: could not keep mode of $filez"
fi
if ! cp "$tmp" "$filegz" 2> /dev/null; then
echo "$prog: warning: could not keep mode of $filez"
if ! cp -f "$tmp" "$filegz" 2> /dev/null; then
echo "$prog: could not copy $tmp to $filegz"
rm -f "$filegz" "$tmp"
return 1
fi
fi
if ! touch -fr "$filez" "$filegz"; then
echo -n "$prog: warning: could not keep timestamp of "
echo "$filez"
fi
rm -f "$filez" "$tmp"
else
echo "$prog: failed to process $filez"
rm -f "$tmp"
return 1
fi
}
prog=`basename "$0"`
usage="usage: $prog [-ftv9K] file ..."
fflag=0
tflag=0
kflag=0
gzipflags=
# -P flag is recognized to maintain compatibility, but ignored. Pipe mode is
# always used
while getopts :ftv9PK i; do
case $i in
f) fflag=1;;
t) tflag=1;;
v) gzipflags="-v $gzipflags";;
9) gzipflags="-9 $gzipflags";;
P) ;;
K) kflag=1;;
\?) echo "$usage"; exit 1;;
esac
done
shift OPTIND-1
if test $# -eq 0; then
echo "$usage"
exit 1
fi
rc=0
while test $# -ne 0; do
if ! process "$1"; then
rc=$?
fi
shift
done
exit $rc

71
usr.bin/gzip/znew.1 Normal file
View File

@ -0,0 +1,71 @@
.\" $NetBSD: znew.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
.\" $OpenBSD: znew.1,v 1.1 2003/08/02 20:52:50 otto Exp $
.\"
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" $FreeBSD$
.Dd January 26, 2007
.Dt ZNEW 1
.Os
.Sh NAME
.Nm znew
.Nd convert compressed files to gzipped files
.Sh SYNOPSIS
.Nm
.Op Fl ftv9K
.Ar
.Sh DESCRIPTION
The
.Nm
utility uncompresses files compressed by
.Xr compress 1
and recompresses them with
.Xr gzip 1 .
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl f
Overwrite existing
.Sq .gz
files.
Unless this option is specified,
.Nm
refuses to overwrite existing files.
.It Fl t
Test integrity of the gzipped file before deleting the original file.
If the integrity check fails, the original
.Sq .Z
file is not removed.
.It Fl v
Print a report specifying the achieved compression ratios.
.It Fl 9
Use the -9 mode of
.Xr gzip 1 ,
achieving better compression at the cost of slower execution.
.It Fl K
Keep the original
.Sq .Z
file if it uses less disk blocks than the gzipped one.
A disk block is 1024 bytes.
.El
.Sh SEE ALSO
.Xr gzip 1
.Sh CAVEATS
The
.Nm
utility tries to maintain the file mode of the original file.
If the original file is not writable, it is not able to do that and
.Nm
will print a warning.

390
usr.bin/gzip/zuncompress.c Normal file
View File

@ -0,0 +1,390 @@
/* $NetBSD: zuncompress.c,v 1.6 2005/11/22 09:05:30 mrg Exp $ */
/*-
* Copyright (c) 1985, 1986, 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Diomidis Spinellis and James A. Woods, derived from original
* work by Spencer Thomas and Joseph Orost.
*
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* from: NetBSD: zopen.c,v 1.8 2003/08/07 11:13:29 agc Exp
* $FreeBSD$
*/
/* This file is #included by gzip.c */
static int zread(void *, char *, int);
#define tab_prefixof(i) (zs->zs_codetab[i])
#define tab_suffixof(i) ((char_type *)(zs->zs_htab))[i]
#define de_stack ((char_type *)&tab_suffixof(1 << BITS))
#define BITS 16 /* Default bits. */
#define HSIZE 69001 /* 95% occupancy */ /* XXX may not need HSIZE */
#define BIT_MASK 0x1f /* Defines for third byte of header. */
#define BLOCK_MASK 0x80
#define CHECK_GAP 10000 /* Ratio check interval. */
#define BUFSIZE (64 * 1024)
/*
* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
* a fourth header byte (for expansion).
*/
#define INIT_BITS 9 /* Initial number of bits/code. */
/*
* the next two codes should not be changed lightly, as they must not
* lie within the contiguous general code space.
*/
#define FIRST 257 /* First free entry. */
#define CLEAR 256 /* Table clear output code. */
#define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
typedef long code_int;
typedef long count_int;
typedef u_char char_type;
static char_type magic_header[] =
{'\037', '\235'}; /* 1F 9D */
static char_type rmask[9] =
{0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
/* XXX zuncompress global */
off_t total_compressed_bytes;
size_t compressed_prelen;
char *compressed_pre;
struct s_zstate {
FILE *zs_fp; /* File stream for I/O */
char zs_mode; /* r or w */
enum {
S_START, S_MIDDLE, S_EOF
} zs_state; /* State of computation */
int zs_n_bits; /* Number of bits/code. */
int zs_maxbits; /* User settable max # bits/code. */
code_int zs_maxcode; /* Maximum code, given n_bits. */
code_int zs_maxmaxcode; /* Should NEVER generate this code. */
count_int zs_htab [HSIZE];
u_short zs_codetab [HSIZE];
code_int zs_hsize; /* For dynamic table sizing. */
code_int zs_free_ent; /* First unused entry. */
/*
* Block compression parameters -- after all codes are used up,
* and compression rate changes, start over.
*/
int zs_block_compress;
int zs_clear_flg;
long zs_ratio;
count_int zs_checkpoint;
int zs_offset;
long zs_in_count; /* Length of input. */
long zs_bytes_out; /* Length of compressed output. */
long zs_out_count; /* # of codes output (for debugging). */
char_type zs_buf[BITS];
union {
struct {
long zs_fcode;
code_int zs_ent;
code_int zs_hsize_reg;
int zs_hshift;
} w; /* Write paramenters */
struct {
char_type *zs_stackp;
int zs_finchar;
code_int zs_code, zs_oldcode, zs_incode;
int zs_roffset, zs_size;
char_type zs_gbuf[BITS];
} r; /* Read parameters */
} u;
};
static code_int getcode(struct s_zstate *zs);
static off_t
zuncompress(FILE *in, FILE *out, char *pre, size_t prelen,
off_t *compressed_bytes)
{
off_t bin, bout = 0;
char *buf;
buf = malloc(BUFSIZE);
if (buf == NULL)
return -1;
/* XXX */
compressed_prelen = prelen;
if (prelen != 0)
compressed_pre = pre;
else
compressed_pre = NULL;
while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) {
if (tflag == 0 && fwrite(buf, 1, bin, out) != (size_t)bin) {
free(buf);
return -1;
}
bout += bin;
}
if (compressed_bytes)
*compressed_bytes = total_compressed_bytes;
free(buf);
return bout;
}
static int
zclose(void *zs)
{
free(zs);
/* We leave the caller to close the fd passed to zdopen() */
return 0;
}
FILE *
zdopen(int fd)
{
struct s_zstate *zs;
if ((zs = calloc(1, sizeof(struct s_zstate))) == NULL)
return (NULL);
zs->zs_state = S_START;
/* XXX we can get rid of some of these */
zs->zs_hsize = HSIZE; /* For dynamic table sizing. */
zs->zs_free_ent = 0; /* First unused entry. */
zs->zs_block_compress = BLOCK_MASK;
zs->zs_clear_flg = 0; /* XXX we calloc()'d this structure why = 0? */
zs->zs_ratio = 0;
zs->zs_checkpoint = CHECK_GAP;
zs->zs_in_count = 1; /* Length of input. */
zs->zs_out_count = 0; /* # of codes output (for debugging). */
zs->u.r.zs_roffset = 0;
zs->u.r.zs_size = 0;
/*
* Layering compress on top of stdio in order to provide buffering,
* and ensure that reads and write work with the data specified.
*/
if ((zs->zs_fp = fdopen(fd, "r")) == NULL) {
free(zs);
return NULL;
}
return funopen(zs, zread, NULL, NULL, zclose);
}
/*
* Decompress read. This routine adapts to the codes in the file building
* the "string" table on-the-fly; requiring no table to be stored in the
* compressed file. The tables used herein are shared with those of the
* compress() routine. See the definitions above.
*/
static int
zread(void *cookie, char *rbp, int num)
{
u_int count, i;
struct s_zstate *zs;
u_char *bp, header[3];
if (num == 0)
return (0);
zs = cookie;
count = num;
bp = (u_char *)rbp;
switch (zs->zs_state) {
case S_START:
zs->zs_state = S_MIDDLE;
break;
case S_MIDDLE:
goto middle;
case S_EOF:
goto eof;
}
/* Check the magic number */
for (i = 0; i < 3 && compressed_prelen; i++, compressed_prelen--)
header[i] = *compressed_pre++;
if (fread(header + i, 1, sizeof(header) - i, zs->zs_fp) !=
sizeof(header) - i ||
memcmp(header, magic_header, sizeof(magic_header)) != 0) {
errno = EFTYPE;
return (-1);
}
total_compressed_bytes = 0;
zs->zs_maxbits = header[2]; /* Set -b from file. */
zs->zs_block_compress = zs->zs_maxbits & BLOCK_MASK;
zs->zs_maxbits &= BIT_MASK;
zs->zs_maxmaxcode = 1L << zs->zs_maxbits;
if (zs->zs_maxbits > BITS) {
errno = EFTYPE;
return (-1);
}
/* As above, initialize the first 256 entries in the table. */
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0; zs->u.r.zs_code--) {
tab_prefixof(zs->u.r.zs_code) = 0;
tab_suffixof(zs->u.r.zs_code) = (char_type) zs->u.r.zs_code;
}
zs->zs_free_ent = zs->zs_block_compress ? FIRST : 256;
zs->u.r.zs_finchar = zs->u.r.zs_oldcode = getcode(zs);
if (zs->u.r.zs_oldcode == -1) /* EOF already? */
return (0); /* Get out of here */
/* First code must be 8 bits = char. */
*bp++ = (u_char)zs->u.r.zs_finchar;
count--;
zs->u.r.zs_stackp = de_stack;
while ((zs->u.r.zs_code = getcode(zs)) > -1) {
if ((zs->u.r.zs_code == CLEAR) && zs->zs_block_compress) {
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0;
zs->u.r.zs_code--)
tab_prefixof(zs->u.r.zs_code) = 0;
zs->zs_clear_flg = 1;
zs->zs_free_ent = FIRST - 1;
if ((zs->u.r.zs_code = getcode(zs)) == -1) /* O, untimely death! */
break;
}
zs->u.r.zs_incode = zs->u.r.zs_code;
/* Special case for KwKwK string. */
if (zs->u.r.zs_code >= zs->zs_free_ent) {
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar;
zs->u.r.zs_code = zs->u.r.zs_oldcode;
}
/* Generate output characters in reverse order. */
while (zs->u.r.zs_code >= 256) {
*zs->u.r.zs_stackp++ = tab_suffixof(zs->u.r.zs_code);
zs->u.r.zs_code = tab_prefixof(zs->u.r.zs_code);
}
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar = tab_suffixof(zs->u.r.zs_code);
/* And put them out in forward order. */
middle: do {
if (count-- == 0)
return (num);
*bp++ = *--zs->u.r.zs_stackp;
} while (zs->u.r.zs_stackp > de_stack);
/* Generate the new entry. */
if ((zs->u.r.zs_code = zs->zs_free_ent) < zs->zs_maxmaxcode) {
tab_prefixof(zs->u.r.zs_code) = (u_short) zs->u.r.zs_oldcode;
tab_suffixof(zs->u.r.zs_code) = zs->u.r.zs_finchar;
zs->zs_free_ent = zs->u.r.zs_code + 1;
}
/* Remember previous code. */
zs->u.r.zs_oldcode = zs->u.r.zs_incode;
}
zs->zs_state = S_EOF;
eof: return (num - count);
}
/*-
* Read one code from the standard input. If EOF, return -1.
* Inputs:
* stdin
* Outputs:
* code or -1 is returned.
*/
static code_int
getcode(struct s_zstate *zs)
{
code_int gcode;
int r_off, bits, i;
char_type *bp;
bp = zs->u.r.zs_gbuf;
if (zs->zs_clear_flg > 0 || zs->u.r.zs_roffset >= zs->u.r.zs_size ||
zs->zs_free_ent > zs->zs_maxcode) {
/*
* If the next entry will be too big for the current gcode
* size, then we must increase the size. This implies reading
* a new buffer full, too.
*/
if (zs->zs_free_ent > zs->zs_maxcode) {
zs->zs_n_bits++;
if (zs->zs_n_bits == zs->zs_maxbits) /* Won't get any bigger now. */
zs->zs_maxcode = zs->zs_maxmaxcode;
else
zs->zs_maxcode = MAXCODE(zs->zs_n_bits);
}
if (zs->zs_clear_flg > 0) {
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
zs->zs_clear_flg = 0;
}
/* XXX */
for (i = 0; i < zs->zs_n_bits && compressed_prelen; i++, compressed_prelen--)
zs->u.r.zs_gbuf[i] = *compressed_pre++;
zs->u.r.zs_size = fread(zs->u.r.zs_gbuf + i, 1, zs->zs_n_bits - i, zs->zs_fp);
zs->u.r.zs_size += i;
if (zs->u.r.zs_size <= 0) /* End of file. */
return (-1);
zs->u.r.zs_roffset = 0;
total_compressed_bytes += zs->u.r.zs_size;
/* Round size down to integral number of codes. */
zs->u.r.zs_size = (zs->u.r.zs_size << 3) - (zs->zs_n_bits - 1);
}
r_off = zs->u.r.zs_roffset;
bits = zs->zs_n_bits;
/* Get to the first byte. */
bp += (r_off >> 3);
r_off &= 7;
/* Get first part (low order bits). */
gcode = (*bp++ >> r_off);
bits -= (8 - r_off);
r_off = 8 - r_off; /* Now, roffset into gcode word. */
/* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
if (bits >= 8) {
gcode |= *bp++ << r_off;
r_off += 8;
bits -= 8;
}
/* High order bits. */
gcode |= (*bp & rmask[bits]) << r_off;
zs->u.r.zs_roffset += zs->zs_n_bits;
return (gcode);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,352 @@
/*-
* Copyright (c) 2006 Shteryana Shopova <syrinx@FreeBSD.org>
* 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. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
* Bridge MIB implementation for SNMPd.
*
* $FreeBSD$
*/
#ifndef SNMP_BRIDGE_H
#define SNMP_BRIDGE_H
#define SNMP_BRIDGE_ID_LEN 8
typedef uint8_t port_id[2];
typedef u_char bridge_id[SNMP_BRIDGE_ID_LEN];
#define SNMP_BRIDGE_MAX_PRIORITY 65535
#define SNMP_BRIDGE_MIN_AGE_TIME 10
#define SNMP_BRIDGE_MAX_AGE_TIME 1000000
#define SNMP_BRIDGE_MIN_TXHC 1
#define SNMP_BRIDGE_MAX_TXHC 10
#define SNMP_BRIDGE_MIN_MAGE 600
#define SNMP_BRIDGE_MAX_MAGE 4000
#define SNMP_BRIDGE_MIN_HTIME 100
#define SNMP_BRIDGE_MAX_HTIME 1000
#define SNMP_BRIDGE_MIN_FDELAY 400
#define SNMP_BRIDGE_MAX_FDELAY 3000
#define SNMP_PORT_PATHCOST_OBSOLETE 65535
#define SNMP_PORT_MIN_PATHCOST 0
#define SNMP_PORT_MAX_PATHCOST 200000000
#define SNMP_PORT_PATHCOST_AUTO 0
#define SNMP_BRIDGE_DATA_MAXAGE 10
#define SNMP_BRIDGE_DATA_MAXAGE_MIN 1
#define SNMP_BRIDGE_DATA_MAXAGE_MAX 300
/* By default poll kernel data every 5 minutes. */
#define SNMP_BRIDGE_POLL_INTERVAL (5 * 60)
#define SNMP_BRIDGE_POLL_INTERVAL_MIN 1
#define SNMP_BRIDGE_POLL_INTERVAL_MAX 3600
/* Poll for a topology change once every 30 seconds. */
#define SNMP_BRIDGE_TC_POLL_INTERVAL 30
struct bridge_if *bridge_get_default(void);
void bridge_set_default(struct bridge_if *bif);
const char *bridge_get_default_name(void);
int bridge_get_data_maxage(void);
/*
* Bridge Addresses Table.
*/
struct tp_entry {
uint32_t sysindex; /* The bridge if sysindex. */
int32_t port_no;
enum TpFdbStatus status;
uint8_t tp_addr[ETHER_ADDR_LEN];
uint8_t flags;
TAILQ_ENTRY(tp_entry) tp_e;
};
/*
* Bridge ports.
* The bridge port system interface index is used for a
* port number. Transparent bridging statistics and STP
* information for a port are also contained here.
*/
struct bridge_port {
/* dot1dBase subtree objects. */
uint32_t sysindex; /* The bridge interface sysindex. */
int32_t port_no; /* The bridge member system index. */
int32_t if_idx; /* SNMP ifIndex from mibII. */
int8_t span_enable; /* Span flag set - private MIB. */
struct asn_oid circuit; /* Unused. */
uint32_t dly_ex_drops; /* Drops on output. */
uint32_t dly_mtu_drops; /* MTU exceeded drops. */
int32_t status; /* The entry status. */
/* dot1dStp subtree objects. */
int32_t path_cost;
int32_t priority;
int32_t design_cost;
uint32_t fwd_trans;
char p_name[IFNAMSIZ]; /* Not in BRIDGE-MIB. */
enum StpPortState state;
enum dot1dStpPortEnable enable;
port_id design_port;
bridge_id design_root;
bridge_id design_bridge;
/* rstpMib extensions. */
int32_t admin_path_cost;
enum TruthValue proto_migr;
enum TruthValue admin_edge;
enum TruthValue oper_edge;
enum TruthValue oper_ptp;
enum StpPortAdminPointToPointType admin_ptp;
/* dot1dTp subtree objects. */
int32_t max_info;
int32_t in_frames;
int32_t out_frames;
int32_t in_drops;
uint8_t flags;
TAILQ_ENTRY(bridge_port) b_p;
};
/*
* A bridge interface.
* The system interface index of the bridge is not required neither by the
* standard BRIDGE-MIB nor by the private BEGEMOT-BRIDGE-MIB, but is used
* as key for looking up the other info for this bridge.
*/
struct bridge_if {
/* dot1dBase subtree objects. */
uint32_t sysindex; /* The system interface index. */
int32_t num_ports; /* Number of ports. */
enum BaseType br_type; /* Bridge type. */
enum RowStatus if_status; /* Bridge status. */
char bif_name[IFNAMSIZ]; /* Bridge interface name. */
struct ether_addr br_addr; /* Bridge address. */
struct bridge_port *f_bp; /* This bridge's first entry
* in the base ports TAILQ. */
/* dot1dStp subtree objects. */
int32_t priority;
int32_t root_cost;
int32_t root_port;
int32_t max_age; /* Current max age. */
int32_t hello_time; /* Current hello time. */
int32_t fwd_delay; /* Current forward delay. */
int32_t hold_time;
int32_t bridge_max_age; /* Configured max age. */
int32_t bridge_hello_time; /* Configured hello time. */
int32_t bridge_fwd_delay; /* Configured forward delay. */
int32_t tx_hold_count;
uint32_t top_changes;
enum dot1dStpVersion stp_version;
enum dot1dStpProtocolSpecification prot_spec;
struct timeval last_tc_time;
bridge_id design_root;
/* dot1dTp subtree objects. */
int32_t lrnt_drops; /* Dropped addresses. */
int32_t age_time; /* Address entry timeout. */
int32_t num_addrs; /* Current # of addresses in cache. */
int32_t max_addrs; /* Max # of addresses in cache. */
struct tp_entry *f_tpa; /* This bridge's first entry in
* the tp addresses TAILQ. */
time_t entry_age;
time_t ports_age;
time_t addrs_age;
TAILQ_ENTRY(bridge_if) b_if;
};
void bridge_ifs_fini(void);
struct bridge_if *bridge_if_find_ifs(uint32_t sysindex);
struct bridge_if *bridge_if_find_ifname(const char *b_name);
const char *bridge_if_find_name(uint32_t sysindex);
int bridge_compare_sysidx(uint32_t i1, uint32_t i2);
int bridge_attach_newif(struct mibif *ifp);
struct bridge_if *bridge_first_bif(void);
struct bridge_if *bridge_next_bif(struct bridge_if *b_pr);
void bridge_remove_bif(struct bridge_if *bif);
void bridge_update_all_ports(void);
void bridge_update_all_addrs(void);
void bridge_update_all_ifs(void);
void bridge_update_all(void *arg);
void bridge_update_tc_time(void *arg);
void bridge_ifs_dump(void);
/* Bridge ports. */
void bridge_ports_update_listage(void);
void bridge_ports_fini(void);
void bridge_members_free(struct bridge_if *bif);
struct bridge_port *bridge_new_port(struct mibif *mif, struct bridge_if *bif);
void bridge_port_remove(struct bridge_port *bp, struct bridge_if *bif);
struct bridge_port *bridge_port_bif_first(struct bridge_if *bif);
struct bridge_port *bridge_port_bif_next(struct bridge_port *bp);
struct bridge_port *bridge_port_find(int32_t if_idx, struct bridge_if *bif);
void bridge_port_getinfo_mibif(struct mibif *m_if, struct bridge_port *bp);
int bridge_getinfo_bif_ports(struct bridge_if *bif);
int bridge_update_memif(struct bridge_if *bif);
void bridge_ports_dump(struct bridge_if *bif);
/* Bridge addresses. */
void bridge_addrs_update_listage(void);
void bridge_addrs_fini(void);
void bridge_addrs_free(struct bridge_if *bif);
struct tp_entry *bridge_new_addrs(uint8_t *mac, struct bridge_if *bif);
void bridge_addrs_remove(struct tp_entry *te, struct bridge_if *bif);
struct tp_entry *bridge_addrs_find(uint8_t *mac, struct bridge_if *bif);
struct tp_entry *bridge_addrs_bif_first(struct bridge_if *bif);
struct tp_entry *bridge_addrs_bif_next(struct tp_entry *te);
int bridge_getinfo_bif_addrs(struct bridge_if *bif);
int bridge_update_addrs(struct bridge_if *bif);
void bridge_addrs_dump(struct bridge_if *bif);
/* Bridge PF. */
void bridge_pf_dump(void);
/* System specific. */
/* Open the socket for the ioctls. */
int bridge_ioctl_init(void);
/* Load bridge kernel module. */
int bridge_kmod_load(void);
/* Get the bridge interface information. */
int bridge_getinfo_bif(struct bridge_if *bif);
/* Get the bridge interface STP parameters. */
int bridge_get_op_param(struct bridge_if *bif);
/* Set the bridge priority. */
int bridge_set_priority(struct bridge_if *bif, int32_t priority);
/* Set the bridge max age. */
int bridge_set_maxage(struct bridge_if *bif, int32_t max_age);
/* Set the bridge hello time.*/
int bridge_set_hello_time(struct bridge_if *bif, int32_t hello_time);
/* Set the bridge forward delay.*/
int bridge_set_forward_delay(struct bridge_if *bif, int32_t fwd_delay);
/* Set the bridge address cache max age. */
int bridge_set_aging_time(struct bridge_if *bif, int32_t age_time);
/* Set the max number of entries in the bridge address cache. */
int bridge_set_max_cache(struct bridge_if *bif, int32_t max_cache);
/* Set the bridge TX hold count. */
int bridge_set_tx_hold_count(struct bridge_if *bif, int32_t tx_hc);
/* Set the bridge STP protocol version. */
int bridge_set_stp_version(struct bridge_if *bif, int32_t stp_proto);
/* Set the bridge interface status to up/down. */
int bridge_set_if_up(const char* b_name, int8_t up);
/* Create a bridge interface. */
int bridge_create(const char *b_name);
/* Destroy a bridge interface. */
int bridge_destroy(const char *b_name);
/* Fetch the bridge mac address. */
u_char *bridge_get_basemac(const char *bif_name, u_char *mac, size_t mlen);
/* Set a bridge member priority. */
int bridge_port_set_priority(const char *bif_name, struct bridge_port *bp,
int32_t priority);
/* Set a bridge member STP-enabled flag. */
int bridge_port_set_stp_enable(const char *bif_name, struct bridge_port *bp,
uint32_t enable);
/* Set a bridge member STP path cost. */
int bridge_port_set_path_cost(const char *bif_name, struct bridge_port *bp,
int32_t path_cost);
/* Set admin point-to-point link. */
int bridge_port_set_admin_ptp(const char *bif_name, struct bridge_port *bp,
uint32_t admin_ptp);
/* Set admin edge. */
int bridge_port_set_admin_edge(const char *bif_name, struct bridge_port *bp,
uint32_t enable);
/* Add a bridge member port. */
int bridge_port_addm(struct bridge_port *bp, const char *b_name);
/* Delete a bridge member port. */
int bridge_port_delm(struct bridge_port *bp, const char *b_name);
/* Get the current value from the module for bridge PF control. */
int32_t bridge_get_pfval(uint8_t which);
/* Get/Set a bridge PF control. */
int32_t bridge_do_pfctl(int32_t bridge_ctl, enum snmp_op op, int32_t *val);
#endif /* SNMP_BRIDGE_H */