Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6724 → Rev 6725

/programs/fs/unzip60/unix/Contents
0,0 → 1,14
Contents of the "unix" subdirectory for UnZip 6.0 and later:
 
Contents this file
Makefile makefile for UnZip for various architectures and OS's
configure automatic build configuration script
unix.c Unix-specific support routines
unxcfg.h Unix-specific configuration settings
zipgrep script to scan zip archive entries for lines matching a pattern
Packaging/ subdirectory containing SysV.4 (e.g., Solaris 2.x) package info
 
Type "make" or "make help" to get general compile instructions (beyond
those in the INSTALL file), or "make list" for a list of makefile targets.
Note that there are some MS-DOS and cross-compilation targets thrown in
just to make things more exciting.
/programs/fs/unzip60/unix/Makefile
0,0 → 1,1026
#==============================================================================
# Makefile for UnZip, UnZipSFX and fUnZip: Unix and MS-DOS ("real" makes only)
# Version: 6.0 18 Jan 2009
#==============================================================================
 
 
# INSTRUCTIONS (such as they are):
#
# "make sunos" -- makes UnZip in current directory on a generic SunOS 4.x Sun
# "make list" -- lists all supported systems (targets)
# "make help" -- provides pointers on what targets to try if problems occur
# "make wombat" -- chokes and dies if you haven't added the specifics for your
# Wombat 68000 (or whatever) to the systems list
#
# CF are flags for the C compiler. LF are flags for the loader. LF2 are more
# flags for the loader, if they need to be at the end of the line instead of at
# the beginning (for example, some libraries). FL and FL2 are the corre-
# sponding flags for fUnZip. LOCAL_UNZIP is an environment variable that can
# be used to add default C flags to your compile without editing the Makefile
# (e.g., -DDEBUG_STRUC, or -FPi87 on PCs using Microsoft C).
#
# Some versions of make do not define the macro "$(MAKE)"; this is rare, but
# if things don't work, try using "make" instead of "$(MAKE)" in your system's
# makerule. Or try adding the following line to your .login file:
# setenv MAKE "make"
# (That never works--makes that are too stupid to define MAKE are also too
# stupid to look in the environment--but try it anyway for kicks. :-) )
#
# Memcpy and memset are provided for those systems that don't have them; they
# are in fileio.c and will be used if -DZMEM is included in CF. These days
# almost all systems have them.
#
# Be sure to test your new UnZip (and UnZipSFX and fUnZip); successful compila-
# tion does not always imply a working program.
 
 
#####################
# MACRO DEFINITIONS #
#####################
 
# Defaults most systems use (use LOCAL_UNZIP in environment to add flags,
# such as -DDOSWILD).
 
# UnZip flags
CC = cc# try using "gcc" target rather than changing this (CC and LD
LD = $(CC)# must match, else "unresolved symbol: ___main" is possible)
AS = as
LOC = $(D_USE_BZ2) $(LOCAL_UNZIP)
AF = $(LOC)
CFLAGS = -O
CF_NOOPT = -I. -I$(IZ_BZIP2) -DUNIX $(LOC)
CF = $(CFLAGS) $(CF_NOOPT)
LFLAGS1 =
LF = -o unzip$E $(LFLAGS1)
LF2 = -s
 
# UnZipSFX flags
SL = -o unzipsfx$E $(LFLAGS1)
SL2 = $(LF2)
 
# fUnZip flags
FL = -o funzip$E $(LFLAGS1)
FL2 = $(LF2)
 
# general-purpose stuff
#CP = cp
CP = ln
LN = ln
RM = rm -f
CHMOD = chmod
BINPERMS = 755
MANPERMS = 644
STRIP = strip
E =
O = .o
M = unix
SHELL = /bin/sh
MAKEF = -f unix/Makefile
 
# Version info for unix/unix.c
HOST_VERSINFO=-DIZ_CC_NAME='\"\$$(CC) \"' -DIZ_OS_NAME='\"`uname -a`\"'
 
# defaults for crc32 stuff and system dependent headers
CRCA_O =
OSDEP_H = unix/unxcfg.h
# default for dependency on auto-configure result, is an empty symbol
# so that the static non-autoconfigure targets continue to work
ACONF_DEP =
 
# optional inclusion of bzip2 decompression
IZ_OUR_BZIP2_DIR = bzip2
IZ_BZIP2 = $(IZ_OUR_BZIP2_DIR)
## The following symbols definitions need to be set to activate bzip2 support:
#D_USE_BZ2 = -DUSE_BZIP2
#L_BZ2 = -lbz2
#LIBBZ2 = $(IZ_BZIP2)/libbz2.a
 
# defaults for unzip's "built-in" bzip2 library compilation
CC_BZ = $(CC)
CFLAGS_BZ = $(CFLAGS)
 
# object files
OBJS1 = unzip$O crc32$O $(CRCA_O) crypt$O envargs$O explode$O
OBJS2 = extract$O fileio$O globals$O inflate$O list$O match$O
OBJS3 = process$O ttyio$O ubz2err$O unreduce$O unshrink$O zipinfo$O
OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $M$O
LOBJS = $(OBJS)
OBJSDLL = $(OBJS:.o=.pic.o) api.pic.o
OBJX = unzipsfx$O crc32_$O $(CRCA_O) crypt_$O extract_$O fileio_$O \
globals_$O inflate_$O match_$O process_$O ttyio_$O ubz2err_$O $M_$O
LOBJX = $(OBJX)
OBJF = funzip$O crc32$O $(CRCA_O) cryptf$O globalsf$O inflatef$O ttyiof$O
#OBJS_OS2 = $(OBJS1:.o=.obj) $(OBJS2:.o=.obj) os2.obj
#OBJF_OS2 = $(OBJF:.o=.obj)
UNZIP_H = unzip.h unzpriv.h globals.h $(OSDEP_H) $(ACONF_DEP)
 
# installation
# (probably can change next two to `install' and `install -d' if you have it)
INSTALL = cp
INSTALL_PROGRAM = $(INSTALL)
INSTALL_D = mkdir -p
# on some systems, manext=l and MANDIR=/usr/man/man$(manext) may be appropriate
manext = 1
prefix = /usr/local
BINDIR = $(prefix)/bin# where to install executables
MANDIR = $(prefix)/man/man$(manext)# where to install man pages
INSTALLEDBIN = $(BINDIR)/funzip$E $(BINDIR)/unzip$E $(BINDIR)/unzipsfx$E \
$(BINDIR)/zipgrep$E $(BINDIR)/zipinfo$E
INSTALLEDMAN = $(MANDIR)/funzip.$(manext) $(MANDIR)/unzip.$(manext) \
$(MANDIR)/unzipsfx.$(manext) $(MANDIR)/zipgrep.$(manext) \
$(MANDIR)/zipinfo.$(manext)
 
# Solaris 2.x stuff:
PKGDIR = IZunzip
VERSION = Version 6.0
 
UNZIPS = unzip$E funzip$E unzipsfx$E
# this is a little ugly...well, OK, it's a lot ugly:
MANS = man/funzip.1 man/unzip.1 man/unzipsfx.1 man/zipgrep.1 man/zipinfo.1
DOCS = funzip.txt unzip.txt unzipsfx.txt zipgrep.txt zipinfo.txt
 
# list of supported systems/targets in this version
SYSTEMG1 = generic generic_gcc generic_pkg generic_gccpkg
SYSTEMG2 = generic1 generic2 generic3 generic_bz2 generic_zlib generic_shlib
SYSTEMS1 = 386i 3Bx 7300 7300_gcc aix aix_rt amdahl amdahl_eft apollo aviion
SYSTEMS2 = bsd bsdi bsdi_noasm bull coherent convex cray cray_opt cyber_sgi
SYSTEMS3 = cygwin dec dnix encore eta freebsd gcc gould hk68 hp hpux
SYSTEMS4 = isc isc_gcc isi linux linux_dos linux_noasm linux_shlib linux_shlibz
SYSTEMS5 = lynx macosx macosx_gcc minix mips mpeix next next10 next2x next3x
SYSTEMS6 = nextfat osf1 pixel ptx pyramid qnxnto realix regulus rs6000 sco
SYSTEMS7 = sco_dos sco_sl sco_x286 sequent sgi solaris solaris_pkg stardent
SYSTEMS8 = stellar sunos3 sunos4 sysv sysv_gcc sysv6300 tahoe ti_sysv ultrix
SYSTEMS9 = vax v7 wombat xenix xos
 
 
####################
# DEFAULT HANDLING #
####################
 
# By default, print help on which makefile targets to try. (The SYSTEM
# variable is no longer supported; use "make <target>" instead.)
 
help:
@echo ""
@echo " If you're not sure about the characteristics of your system, try typing"
@echo " \"make generic\". This is new and uses the configure script, though it is"
@echo " still being worked on."
@echo ""
@echo " If that does not do it, try the original generic which is \"make generic1\"."
@echo ""
@echo " If the compiler barfs and says something unpleasant about \"timezone redefined\","
@echo " try typing \"make clean\" followed by \"make generic2\". If, on the other"
@echo " hand, it complains about an undefined symbol _ftime, try typing \"make clean\""
@echo " followed by \"make generic3\"."
@echo ""
@echo " One of these actions should produce a working copy of unzip on most Unix"
@echo " systems. If you know a bit more about the machine on which you work, you"
@echo " might try \"make list\" for a list of the specific systems supported herein."
@echo " (Many of them do exactly the same thing, so don't agonize too much over"
@echo " which to pick if two or more sound equally likely.) Also check out the"
@echo " INSTALL file for notes on compiling various targets. As a last resort,"
@echo " feel free to read the numerous comments within the Makefile itself."
@echo ""
@echo " Have a mostly pretty good day."
@echo ""
 
list:
@echo ""
@echo\
'Type "make <system>", where <system> is one of the following:'
@echo ""
@echo " $(SYSTEMG1)"
@echo " $(SYSTEMG2)"
@echo ""
@echo " $(SYSTEMS1)"
@echo " $(SYSTEMS2)"
@echo " $(SYSTEMS3)"
@echo " $(SYSTEMS4)"
@echo " $(SYSTEMS5)"
@echo " $(SYSTEMS6)"
@echo " $(SYSTEMS7)"
@echo " $(SYSTEMS8)"
@echo " $(SYSTEMS9)"
# @echo ""
# @echo\
# 'Targets for related utilities (ZipInfo and fUnZip) include:'
# @echo ""
# @echo " $(SYS_UTIL1)"
# @echo " $(SYS_UTIL2)"
@echo ""
@echo\
'For further (very useful) information, please read the comments in Makefile.'
@echo ""
 
generic_msg:
@echo ""
@echo\
' Attempting "make generic" now. If this fails for some reason, type'
@echo\
' "make help" and/or "make list" for suggestions.'
@echo ""
 
 
###############################################
# BASIC COMPILE INSTRUCTIONS AND DEPENDENCIES #
###############################################
 
# this is for GNU make; comment out and notify zip-bugs if it causes errors
.SUFFIXES: .c .o .obj .pic.o
 
# yes, we should be able to use the $O macro to combine these two, but it
# fails on some brain-damaged makes (e.g., AIX's)...no big deal
.c.o:
$(CC) -c $(CF) $*.c
 
.c.obj:
$(CC) -c $(CF) $*.c
 
.c.pic.o:
$(CC) -c $(CF) -o $@ $*.c
 
# this doesn't work...directories are always a pain with implicit rules
#.1.txt: man/$<
# nroff -Tman -man $< | col -b | uniq | \
# sed 's/Sun Release ..../Info-ZIP /' > $@
 
 
# these rules may be specific to Linux (or at least the GNU groff package)
# and are really intended only for the authors' use in creating non-Unix
# documentation files (which are provided with both source and binary
# distributions). We should probably add a ".1.txt" rule for more generic
# systems...
 
funzip.txt: man/funzip.1
nroff -Tascii -man man/funzip.1 | col -bx | uniq | expand > $@
 
unzip.txt: man/unzip.1
nroff -Tascii -man man/unzip.1 | col -bx | uniq | expand > $@
 
unzipsfx.txt: man/unzipsfx.1
nroff -Tascii -man man/unzipsfx.1 | col -bx | uniq | expand > $@
 
zipgrep.txt: man/zipgrep.1
nroff -Tascii -man man/zipgrep.1 | col -bx | uniq | expand > $@
 
zipinfo.txt: man/zipinfo.1
nroff -Tascii -man man/zipinfo.1 | col -bx | uniq | expand > $@
 
 
all: generic_msg generic
unzips: $(UNZIPS)
objs: $(OBJS)
objsdll: $(OBJSDLL)
docs: $(DOCS)
unzipsman: unzips docs
unzipsdocs: unzips docs
 
 
# EDIT HERE FOR PARALLEL MAKES on Sequent (and others?)--screws up MS-DOS
# make utilities if default: change "unzip$E:" to "unzip$E:&"
 
unzip$E: $(OBJS) $(LIBBZ2) # add `&' for parallel makes
$(LD) $(LF) -L$(IZ_BZIP2) $(LOBJS) $(L_BZ2) $(LF2)
 
unzipsfx$E: $(OBJX) # add `&' for parallel makes
$(LD) $(SL) $(LOBJX) $(SL2)
 
funzip$E: $(OBJF) # add `&' for parallel makes
$(LD) $(FL) $(OBJF) $(FL2)
 
zipinfo$E: unzip$E # `&' is pointless here...
@echo\
' This is a Unix-specific target. ZipInfo is not enabled in some MS-DOS'
@echo\
' versions of UnZip; if it is in yours, copy unzip.exe to zipinfo.exe'
@echo\
' or else invoke as "unzip -Z" (in a batch file, for example).'
$(LN) unzip$E zipinfo$E
 
# when the optional bzip2 support is provided (as recommended) by sources
# in the 'bzip2' subdirectory, create/update the library:
$(IZ_OUR_BZIP2_DIR)/libbz2.a:
@echo "Building/updating bzip2 object library..."
( cd $(IZ_OUR_BZIP2_DIR) ; $(MAKE) -f Makebz2.iz CC="$(CC_BZ)"\
CFLAGS="$(CFLAGS_BZ)" RM="rm -f" )
 
 
crc32$O: crc32.c $(UNZIP_H) zip.h crc32.h
crypt$O: crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
envargs$O: envargs.c $(UNZIP_H)
explode$O: explode.c $(UNZIP_H)
extract$O: extract.c $(UNZIP_H) crc32.h crypt.h
fileio$O: fileio.c $(UNZIP_H) crc32.h crypt.h ttyio.h ebcdic.h
funzip$O: funzip.c $(UNZIP_H) crc32.h crypt.h ttyio.h
globals$O: globals.c $(UNZIP_H)
inflate$O: inflate.c inflate.h $(UNZIP_H)
list$O: list.c $(UNZIP_H)
match$O: match.c $(UNZIP_H)
process$O: process.c $(UNZIP_H) crc32.h
ttyio$O: ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
ubz2err$O: ubz2err.c $(UNZIP_H)
unreduce$O: unreduce.c $(UNZIP_H)
unshrink$O: unshrink.c $(UNZIP_H)
unzip$O: unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
zipinfo$O: zipinfo.c $(UNZIP_H)
 
# unzipsfx compilation section
unzipsfx$O: unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
$(CC) -c $(CF) -DSFX -o $@ unzip.c
 
crc32_$O: crc32.c $(UNZIP_H) zip.h crc32.h
$(CC) -c $(CF) -DSFX -o $@ crc32.c
 
crypt_$O: crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
$(CC) -c $(CF) -DSFX -o $@ crypt.c
 
extract_$O: extract.c $(UNZIP_H) crc32.h crypt.h
$(CC) -c $(CF) -DSFX -o $@ extract.c
 
fileio_$O: fileio.c $(UNZIP_H) crc32.h crypt.h ttyio.h ebcdic.h
$(CC) -c $(CF) -DSFX -o $@ fileio.c
 
globals_$O: globals.c $(UNZIP_H)
$(CC) -c $(CF) -DSFX -o $@ globals.c
 
inflate_$O: inflate.c inflate.h $(UNZIP_H) crypt.h
$(CC) -c $(CF) -DSFX -o $@ inflate.c
 
match_$O: match.c $(UNZIP_H)
$(CC) -c $(CF) -DSFX -o $@ match.c
 
process_$O: process.c $(UNZIP_H) crc32.h
$(CC) -c $(CF) -DSFX -o $@ process.c
 
ttyio_$O: ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
$(CC) -c $(CF) -DSFX -o $@ ttyio.c
 
ubz2err_$O: ubz2err.c $(UNZIP_H)
$(CC) -c $(CF) -DSFX -o $@ ubz2err.c
 
 
# funzip compilation section
cryptf$O: crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
$(CC) -c $(CF) -DFUNZIP -o $@ crypt.c
 
globalsf$O: globals.c $(UNZIP_H)
$(CC) -c $(CF) -DFUNZIP -o $@ globals.c
 
inflatef$O: inflate.c inflate.h $(UNZIP_H) crypt.h
$(CC) -c $(CF) -DFUNZIP -o $@ inflate.c
 
ttyiof$O: ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
$(CC) -c $(CF) -DFUNZIP -o $@ ttyio.c
 
 
# optional assembler replacements
crc_i86$O: msdos/crc_i86.asm # 16bit only
$(AS) $(AF) msdos/crc_i86.asm $(ASEOL)
 
crc_gcc$O: crc_i386.S $(ACONF_DEP) # 32bit, GNU AS
$(AS) $(AF) -x assembler-with-cpp -c -o $@ crc_i386.S
 
crc_gcc.pic.o: crc_i386.S $(ACONF_DEP) # 32bit, GNU AS
$(AS) $(AF) -x assembler-with-cpp -c -o $@ crc_i386.S
 
crc_sysv$O: crc_i386.S $(ACONF_DEP) # 32bit, SysV AS
$(CC) -E $(AF) crc_i386.S > crc_i386s.s
$(AS) -o $@ crc_i386s.s
$(RM) crc_i386s.s
 
msdos$O: msdos/msdos.c $(UNZIP_H) unzvers.h # DOS only
$(CC) -c $(CF) msdos/msdos.c
 
msdos_$O: msdos/msdos.c $(UNZIP_H) # DOS unzipsfx
-$(CP) msdos/msdos.c msdos_.c > nul
$(CC) -c $(CF) -DSFX msdos_.c
$(RM) msdos_.c
 
#os2$O: os2/os2.c $(UNZIP_H) # OS/2 only
# $(CC) -c $(CF) os2/os2.c
 
unix$O: unix/unix.c $(UNZIP_H) unzvers.h # Unix only
$(CC) -c $(CF) unix/unix.c
 
unix_$O: unix/unix.c $(UNZIP_H) # Unix unzipsfx
$(CC) -c $(CF) -DSFX -o $@ unix/unix.c
 
unix.pic.o: unix/unix.c $(UNZIP_H) unzvers.h # Unix shlib
$(CC) -c $(CF) -o $@ unix/unix.c
 
 
unix_make:
# @echo\
# '(Ignore any errors from `make'"' due to the following command; it's harmless.)"
-@2>&1 $(LN) unix/Makefile . > /dev/null || echo > /dev/null
 
# this really only works for Unix targets, unless E and O specified on cmd line
clean:
@echo ""
@echo ' This is a Unix-specific target. (Just so you know.)'
@echo ""
-( cd $(IZ_OUR_BZIP2_DIR); $(MAKE) -f Makebz2.iz RM="rm -f" clean )
rm -f $(UNZIPS) $(OBJS) $(OBJF) $(OBJX) api$O apihelp$O crc_gcc$O \
crc_sysv$O unzipstb$O crypt_.c extract_.c globals_.c inflate_.c \
ttyio_.c crc_i386s.s msdos_.c process_.c unix_.c unzipsfx.c
rm -f flags
rm -rf ./$(PKGDIR)
 
# Package generation interface (by J.Bush). Originally tested under Sun
# Solaris 2.x. Other SVr4s may be very similar and could possibly use this.
# Note: expects version info to be stored in VERSION macro variable.
# See "README" under ./unix/Packaging
#
svr4package: unzips
@echo "Creating SVR4 package for Unix ..."
-@rm -rf ./$(PKGDIR) ./$(PKGDIR)_`uname -p`.pkg
-@sed -e "s/.VERSION./$(VERSION)/g" \
-e "s/.PSTAMP./$(LOGNAME)_`date | tr ' ' '_'`/g" \
-e "s/.ARCH./Solaris_`uname -rp | tr ' ' ','`/g" \
./unix/Packaging/pkginfo.in > ./unix/Packaging/pkginfo
-@sed -e "s/.ARCH./`uname -p`/g" \
./unix/Packaging/preinstall.in > ./unix/Packaging/preinstall
/usr/bin/pkgmk -d . -b . -r . -f ./unix/Packaging/prototype $(PKGDIR)
/usr/bin/pkgtrans -o -s . $(PKGDIR)_`uname -p`.pkg $(PKGDIR)
@echo " "
@echo "To install, copy $(PKGDIR)_`uname -p`.pkg to the target system, and"
@echo "issue the command (as root): pkgadd -d $(PKGDIR)_`uname -p`.pkg"
@echo " "
 
install: $(MANS)
-$(INSTALL_D) $(BINDIR)
$(INSTALL_PROGRAM) $(UNZIPS) $(BINDIR)
$(INSTALL) unix/zipgrep $(BINDIR)
$(RM) $(BINDIR)/zipinfo$E
$(LN) $(BINDIR)/unzip$E $(BINDIR)/zipinfo$E
-$(INSTALL_D) $(MANDIR)
$(INSTALL) man/funzip.1 $(MANDIR)/funzip.$(manext)
$(INSTALL) man/unzip.1 $(MANDIR)/unzip.$(manext)
$(INSTALL) man/unzipsfx.1 $(MANDIR)/unzipsfx.$(manext)
$(INSTALL) man/zipgrep.1 $(MANDIR)/zipgrep.$(manext)
$(INSTALL) man/zipinfo.1 $(MANDIR)/zipinfo.$(manext)
$(CHMOD) $(BINPERMS) $(INSTALLEDBIN)
$(CHMOD) $(MANPERMS) $(INSTALLEDMAN)
 
uninstall:
$(RM) $(INSTALLEDBIN) $(INSTALLEDMAN)
 
# added 10/28/04 EG
flags: unix/configure
sh unix/configure "${CC}" "${CF_NOOPT}" "${IZ_BZIP2}"
 
# the test zipfile
TESTZIP = testmake.zip
 
# test some basic features of the build
test: check
 
check:
@echo '##### This is a Unix-specific target. (Just so you know.)'
@echo '##### Make sure unzip, funzip and unzipsfx are compiled and'
@echo '##### in this directory.'
@if test ! -f ./unzip; then \
echo "##### ERROR: can't find ./unzip"; exit 1; fi
@if test ! -f ./funzip; then \
echo "##### ERROR: can't find ./funzip"; exit 1; fi
@if test ! -f ./unzipsfx; then \
echo "##### ERROR: can't find ./unzipsfx"; exit 1; fi
#
@if test ! -f $(TESTZIP); then \
echo "##### ERROR: can't find test file $(TESTZIP)"; exit 1; fi
#
@echo "##### testing extraction"
@./unzip -bo $(TESTZIP) testmake.zipinfo
@if test ! -f testmake.zipinfo ; then \
echo "##### ERROR: file extraction from $(TESTZIP) failed"; \
exit 1; fi
#
@echo '##### testing zipinfo (unzip -Z)'
@./unzip -Z $(TESTZIP) > testmake.unzip-Z
@if diff testmake.unzip-Z testmake.zipinfo; then echo "OK."; else \
echo "##### WARNING: zipinfo output doesn't match stored version"; \
echo '##### (If the only difference is the file times, compare your'; \
echo '##### timezone with the Central European timezone, which is one'; \
echo '##### hour east of Greenwich but effectively 2 hours east'; \
echo '##### during summer Daylight Savings Time. The upper two'; \
echo '##### lines should correspond to your local time when the'; \
echo '##### files were created, on 19 November 1998 at 10:46pm CET.'; \
echo '##### If the times are consistent, please ignore this warning.)'; \
fi
@$(RM) testmake.unzip-Z testmake.zipinfo
#
@echo '##### testing unzip -d exdir option'
@./unzip -bo $(TESTZIP) -d testun notes
@cat testun/notes
#
@echo '##### testing unzip -o and funzip (ignore funzip warning)'
@./unzip -boq $(TESTZIP) notes -d testun
@./funzip < $(TESTZIP) > testun/notes2
@if diff testun/notes testun/notes2; then true; else \
echo '##### ERROR: funzip output disagrees with unzip'; fi
#
@echo '##### testing unzipsfx (self-extractor)'
@cat unzipsfx $(TESTZIP) > testsfx
@$(CHMOD) 0700 testsfx
@./testsfx -bo notes
@if diff notes testun/notes; then true; else \
echo '##### ERROR: unzipsfx file disagrees with unzip'; fi
@$(RM) testsfx notes testun/notes testun/notes2
@rmdir testun
#
@echo '##### testing complete.'
 
 
################################
# INDIVIDUAL MACHINE MAKERULES #
################################
 
#----------------------------------------------------------------------------
# Generic targets using the configure script to determine configuration.
#----------------------------------------------------------------------------
 
# Well, try MAKE and see. By now everyone may be happy. 10/28/04 EG
generic: flags # now try autoconfigure first
eval $(MAKE) $(MAKEF) unzips ACONF_DEP=flags `cat flags`
# make $(MAKEF) unzips CF="${CF} `cat flags`"
 
generic_gcc:
$(MAKE) $(MAKEF) generic CC=gcc IZ_BZIP2="$(IZ_BZIP2)"
 
# extensions to perform SVR4 package-creation after compilation
generic_pkg: generic svr4package
generic_gccpkg: generic_gcc svr4package
 
#----------------------------------------------------------------------------
# Old static generic targets (can't assume make utility groks "$(MAKE)")
#----------------------------------------------------------------------------
 
generic1: unzips # first try if unknown
 
generic2: unix_make # second try if unknown: hope make is called "make"
make $(MAKEF) unzips CF="$(CF) -DBSD"
 
generic3: unix_make # third try if unknown: hope make is called "make"
make $(MAKEF) unzips CF="$(CF) -DSYSV"
 
# Generic build including bzip2 decompression support for unzip.
# Requires presence of the bzip2 sources in subdirectory bzip2.
 
generic_bz2: unix_make
@echo\
"This target assumes bzip2 sources are available in subfolder bzip2/."
$(MAKE) $(MAKEF) unzips D_USE_BZ2="-DUSE_BZIP2"\
L_BZ2="-lbz2" LIBBZ2="$(IZ_OUR_BZIP2_DIR)/libbz2.a" \
CC_BZ="$(CC)" CFLAGS_BZ="$(CFLAGS)"
 
# Generic unzip and funzip target using either shared or static zlib for
# inflate rather than the original UnZip version. (libz was libgz prior
# to 0.94) Need to figure out how to force unzipsfx to use static libz.
 
generic_zlib: unix_make
@echo\
"This target assumes zlib (libz.a or libz.so.*) is already installed."
$(MAKE) unzip funzip CF="$(CF) -DUSE_ZLIB" LF2="-lz $(LF2)"
 
# Generic GNU C shared library. This is an example of how to compile UnZip as
# a shared library. (Doing so as a static library would be similar.) See also
# the linux_shlib target.
 
generic_shlib: unix_make
@echo\
'This target requires GNU C. When done, do "setenv LD_LIBRARY_PATH `pwd`"'
@echo\
'or similar in order to test the shared library in place (with ./unzip_shlib ,'
@echo\
'which is UnZip linked with the DLL). This target is an example only.'
@echo ""
$(MAKE) objsdll CC=gcc CFLAGS="-O3 -Wall -fPIC -DDLL"
gcc -shared -Wl,-soname,libunzip.so.0 -o libunzip.so.0.4 $(OBJSDLL)
$(RM) libunzip.so.0 libunzip.so
$(LN) -s libunzip.so.0.4 libunzip.so.0
$(LN) -s libunzip.so.0 libunzip.so
gcc -c -O unzipstb.c
gcc -o unzip_shlib unzipstb.o -L. -lunzip
 
#----------------------------------------------------------------------------
# "Autoconfig" group, aliases for the generic targets using configure:
#----------------------------------------------------------------------------
 
# Solaris: generic, plus generation of installable package.
solaris_pkg: generic_pkg
 
# Solaris: forcing usage of GCC, plus generation of installable package.
solaris_gccpkg: generic_gcc_pkg
 
#----------------------------------------------------------------------------
# "Normal" group (BSD vs. SysV may be set in unzip.h via predefined macros):
#----------------------------------------------------------------------------
 
386i: unzips # sun386i, SunOS 4.0.2
#3Bx: unzips # AT&T 3B2/1000-80; should work on any WE32XXX machine
#aix_rt: unzips # IBM RT 6150 under AIX 2.2.1
bull: unzips # Bull DPX/2, BOS 2.00.45 (doesn't require -Xk switch)
convex: unzips # Convex C-120 and C-210 (-O is enough; -ext is default)
cray: unzips # Cray-2 and Y-MP, using default (possibly old) compiler
dec: unzips # DEC 5820 (MIPS RISC), test version of Ultrix v4.0
encore: unzips # Multimax
eta: unzips # ETA-10P*, hybrid SysV with BSD 4.3 enhancements
gould: unzips # Gould PN9000 running UTX/32 2.1Bu01
hp: unzips # HP 9000 series (68020), 4.3BSD or HP-UX A.B3.10 Ver D
hpux: unzips # (to match zip's makefile entry)
mips: unzips # MIPS M120-5(?), SysV.3 [error in sys/param.h file?]
next10: unzips # NeXT (generic; use next2x or next3x for better opt.)
osf1: unzips # DECstation, including Alpha-based; DEC OSF/1 v1.x
pyr_: unzips # [failsafe target for pyramid target below]
pyr_ucb: unzips # Pyramids running BSD universe by default (see below)
realix: unzips # Modcomp Real/IX (SysV.3); note "gcc" = GLS C, not GNU
sco: unzips # Xenix/386 (tested on 2.3.1); SCO Unix 3.2.0.
sgi: unzips # Silicon Graphics; Irix 3.3.2, 4.0.x, 5.2, etc.
stellar: unzips # gs-2000
sun: unzips # old target; no good with solaris...use "sunos" now
sunos: unzips # no good with SunOS 3.x...use "sunos3" or "sunos4" now
sunos4: unzips # Sun 3, 4; SunOS 4.x (SOME SYSTEMS ARE SYSTEM V!)
tahoe: unzips # tahoe (CCI Power6/32), 4.3BSD
ultrix: unzips # VAXen, DEC 58x0 (MIPS guts), DECstation 2100; v4.x
vax: unzips # general-purpose VAX target (not counting VMS)
 
#----------------------------------------------------------------------------
# BSD group (for timezone structs [struct timeb]):
#----------------------------------------------------------------------------
 
bsd: _bsd # generic BSD (BSD 4.2 & Ultrix handled in unzip.h)
 
_bsd: unix_make
$(MAKE) unzips CF="$(CF) -DBSD"
 
#----------------------------------------------------------------------------
# SysV group (for extern long timezone and ioctl.h instead of sgtty.h):
#----------------------------------------------------------------------------
 
aix_rt: _sysv # IBM RT 6150 under AIX 2.2.1
aviion: _sysv # Data General AViiONs, DG/UX 4.3x
pyr_att: _sysv # Pyramids running AT&T (SysV) universe by default
stardent: _sysv # Stardent ...
sysv: _sysv # generic System V Unix (Xenix handled in unzip.h)
xos: _sysv # Olivetti LSX-3005..3045, X/OS 2.3 and 2.4
 
_sysv: unix_make
$(MAKE) unzips CF="$(CF) -DSYSV"
 
# extension to perform SVR4 package-creation after compilation
_sysvp: _sysv svr4package
 
#----------------------------------------------------------------------------
# Version 7 group (old/obsolescent):
#----------------------------------------------------------------------------
 
pixel: _v7 # Pixel 80, 100 (68000-based, V7/mostly BSD4.1 compat.)
v7: _v7 # generic Unix Version 7 box (prob. only Pixel...)
 
_v7:
make $(MAKEF) unzips \
CF="$(CF) -DV7 -DNO_PARAM_H -DSHORT_NAMES -DBSD -DZMEM -DNO_LCHOWN -DNO_LCHMOD"
 
#----------------------------------------------------------------------------
# "Unique" group (require non-standard options):
#----------------------------------------------------------------------------
 
# AT&T 3B2/1000-80; should work on any WE32XXX machine
3Bx: unix_make
$(MAKE) unzips CF="$(CF) -DCBREAK=2"
 
# AT&T 7300 (M68000/SysV.3) (add -DSYSV? -DNO_LIMITS?)
7300: unix_make
$(MAKE) unzips CF="$(CF) -DNO_DIR -DNO_MKDIR -DNO_STRNICMP -DNO_UID_GID -DNO_FCHMOD -DNO_LCHOWN -DNO_LCHMOD -DCBREAK=2"
 
7300_gcc: unix_make
$(MAKE) unzips CC=gcc LD=gcc LF2="" CFLAGS="-O2" \
LOC="-DNO_DIR -DNO_MKDIR -DNO_STDLIB_H -DNO_STRNICMP -DNO_UID_GID -DNO_FCHMOD -DNO_LCHOWN -DNO_LCHMOD -DCBREAK=2 $(LOC)"
$(STRIP) $(UNZIPS)
 
# IBM AIX 3.x on an RS/6000: see rs6000 target below
aix: rs6000
 
# Amdahl (IBMish) mainframe, UTS (SysV) 1.2.4, 2.0.1, 3.x
amdahl: unix_make
$(MAKE) unzips CF="$(CF) -DSYSV -DNO_UID_GID -DNO_LCHOWN -DNO_LCHMOD"
 
# Amdahl UTS 2.1.4 with "extended file types" filesystem (aarrrggghhhh...)
amdahl_eft: unix_make
$(MAKE) unzips CF="$(CF) -eft -DSYSV -DNO_UID_GID -DNO_LCHOWN -DNO_LCHMOD"
 
# Apollo Domain/OS machines (added -D...SOURCE options) [Gordon Fox, 960810]
apollo: unix_make
$(MAKE) unzips CF="$(CF) -D_INCLUDE_BSD_SOURCE -D_INCLUDE_XOPEN_SOURCE -DNO_LCHOWN -DNO_LCHMOD"
 
# BSDI BSD/OS on 386 platform, using the assembler replacement for crc32.c
bsdi: unix_make
@echo 'NOTE: use bsdi_noasm target for non-Intel BSD/OS compiles.'
$(MAKE) unzips CC=gcc2 LD=shlicc2 AS=gcc2\
CFLAGS="-O3 -Wall -DASM_CRC -DBSD" CRCA_O=crc_gcc$O
 
# BSDI BSD/OS
bsdi_noasm: unix_make
# @echo 'NOTE: use bsd target for non-Intel BSD/OS compiles.'
$(MAKE) unzips CC=gcc2 LD=shlicc2 AS=gcc2\
CFLAGS="-O3 -Wall -DBSD"
 
# Coherent 3.x/4.x, Mark Williams C. ``For Coherent's CC, it needs either
# -T0 or -T150000 (or bigger) added to the CFLAGS, otherwise the compiler
# runs out of memory and dies in zipinfo.c.'' [Fred "Fredex" Smith, 940719]
coherent: unix_make
$(MAKE) unzips CFLAGS="$(CFLAGS) -T0 -DNO_LCHOWN -DNO_LCHMOD"
 
# Cray-2, Y-MP or C90, running Unicos 5.x to 8.x (SysV + BSD enhancements)
# and Standard (ANSI) C compiler 3.0 or later.
cray_opt: unix_make
$(MAKE) unzips CFLAGS="$(CFLAGS) -h scalar3 -h vector3 -DNO_LCHOWN -DNO_LCHMOD"
 
# The unzip41 build on a Cyber 910/SGI running Irix v3.3.3 was successful
# with the following change to Makefile:
cyber_sgi: unix_make
$(MAKE) unzips CFLAGS="$(CFLAGS) -I/usr/include/bsd -DNO_LCHOWN -DNO_LCHMOD"\
LF="-lbsd $(LF)" SL="-lbsd $(SL)"
 
# The Cygwin environment on a Win32 system, treated as an UNIX emulator.
# This port does not offer full access to the Windows file system.
# Info-ZIP recommends using "win32/Makefile.gcc" instead.
cygwin: unix_make
$(MAKE) unzips CC=gcc LD=gcc AS=gcc\
CFLAGS="-O3 -DASM_CRC -DNO_LCHOWN -DNO_LCHMOD"\
AF="-Di386 $(AF)" CRCA_O=crc_gcc$O\
E=".exe" CP="cp" LN="ln -s"
 
# 680x0, DIAB dnix 5.2/5.3 (a Swedish System V clone)
#
# Options for the dnix cc:
# -X7 = cc is strict ANSI C
# -X9 = warnings if a function is used without a declaration
#
dnix: unix_make
$(MAKE) unzips CFLAGS="$(CFLAGS) -X7 -X9 -DDNIX"
 
# FreeBSD on Intel:
freebsd: unix_make
@echo 'NOTE: use bsd target for non-Intel FreeBSD compiles (if any).'
$(MAKE) unzips CC=gcc LD=gcc AS=gcc\
CFLAGS="-O3 -Wall -DASM_CRC -DBSD"\
AF="-Di386 $(AF)" CRCA_O=crc_gcc$O
 
# Generic BSDish Unix gcc. ``The -O3 only works with later versions of gcc;
# you may have to use -O2 or -O for earlier versions. I have no idea why
# -s causes this bug in gcc.'' [Bug: "nm: unzip: no name list", "collect:
# /usr/bin/nm returned 1 exit status".] If you don't have strip, don't
# worry about it (it just makes the executable smaller and can be replaced
# with "echo" instead).
#
gcc: unix_make
$(MAKE) unzips CC=gcc LD=gcc CFLAGS="-O3" LF2=""
$(STRIP) $(UNZIPS)
 
# Heurikon HK68 (68010), UniPlus+ System V 5.0, Green Hills C-68000
hk68: unix_make
$(MAKE) unzips CC="gcc" LD="gcc"\
LF="-n $(LF)" SL="-n $(SL)" FL="-n $(FL)"\
CFLAGS="-ga -X138 -Dlocaltime=localti -Dtimezone=timezon"
 
# ISC Unix on 386 platform
isc: unix_make
$(MAKE) unzips LF2="-lc_s $(LF2)" CRCA_O=crc_sysv$O \
CFLAGS="-O" LOC="-DASM_CRC -DSYSV -DNO_UID_GID -DNEED_PTEM -DNO_LCHOWN -DNO_LCHMOD $(LOC)" \
AF="-DNO_UNDERLINE -Djecxz=jcxz -DALIGNMENT='.align 16' $(AF)"
 
isc_gcc: unix_make
$(MAKE) unzips AS=gcc CC=gcc LD=gcc CRCA_O=crc_gcc$O \
LF="-shlib $(LF)" SL="-shlib $(SL)" FL="-shlib $(FL)" LF2="" \
CFLAGS="-O3" LOC="-DSYSV -DASM_CRC -DNO_UID_GID -DNEED_PTEM -DNO_LCHOWN -DNO_LCHMOD $(LOC)" \
AF="-DNO_UNDERLINE -Djecxz=jcxz -DALIGNMENT='.align 16' $(AF)"
$(STRIP) $(UNZIPS)
 
# "ISI machine (68025 CPU)" (based on e-mail from Rob White <rsw@tfs.com>;
# no further information). May also need DIRENT defined.
isi: unix_make
$(MAKE) unzips CF="$(CF) -DDECLARE_ERRNO -DNO_LCHOWN -DNO_LCHMOD"
 
# Linux on 386 platform, using the assembler replacement for crc32.c. (-O4 and
# -fno-strength-reduce have virtually no effect beyond -O3. Add "-m486
# -malign-functions=2 -malign-jumps=2 -malign-loops=2" for Pentium [Pro]
# systems.)
linux: unix_make
@echo 'NOTE: use linux_noasm target for non-Intel Linux compiles.'
$(MAKE) unzips CC=gcc LD=gcc AS=gcc\
CFLAGS="-O3 -Wall -DASM_CRC"\
AF="-Di386 $(AF)" CRCA_O=crc_gcc$O
# GRR: this echo is pointless; if user gets this far, no difference to install
# @echo 'Be sure to use the install_asm target rather than the install target'
 
linux_asm: linux
 
# Linux (Posix, approximately SysV): virtually any version since before 0.96,
# for any platform. Change "-O" to "-O3" or whatever, as desired...
linux_noasm: unix_make
$(MAKE) unzips CC=gcc LD=gcc CFLAGS="-O -Wall"
 
# Linux with lcc compiler: __inline__ (stat.h) not recognized, and must edit
# /usr/include/gnu/types.h to get rid of "long long" if __LCC__ defined. -O3
# (or -O2 or -O) is ignored. [GRR 960828: test target only]
#
linux_lcc: unix_make
$(MAKE) unzips CC=lcc LD=lcc CFLAGS="-O3 -Wall -D__inline__= "
 
# Linux host with go32 (djgpp) cross-compiler (go32crs.tgz) for 32-bit DOS.
linux_dos: unix_make
$(MAKE) unzips CC=go32gcc LD=go32gcc M=msdos OSDEP_H="msdos/doscfg.h" \
CFLAGS="-O2 -Wall"
# go32-strip unzip
# Due to limitations of the cross-compiling package, this has to be
# done manually:
@echo Copy $(UNZIPS) to your DOS partition and use coff2exe.
 
# Linux ELF shared library (ooo, it's so easy). This is a test target for
# now, and it only makes the UnZip/ZipInfo stuff (not fUnZip or UnZipSFX).
# The version number may eventually change to match the UnZip version. Or
# not. Whatever. Also do "setenv LD_LIBRARY_PATH `pwd`" or similar to test
# the DLL in place (with unzip_shlib, which is UnZip linked with the shared
# library).
#
linux_shlib: unix_make
$(MAKE) objsdll CC=gcc CFLAGS="-O3 -Wall -fPIC"\
LOC="-DDLL -DASM_CRC $(LOC)"\
AS=gcc AF="-fPIC -Di386 $(AF)" CRCA_O=crc_gcc$O
gcc -shared -Wl,-soname,libunzip.so.0 -o libunzip.so.0.4 $(OBJSDLL)\
crc_gcc.pic.o
ln -sf libunzip.so.0.4 libunzip.so.0
ln -sf libunzip.so.0 libunzip.so
gcc -c -O unzipstb.c
gcc -o unzip_shlib unzipstb.o -L. -lunzip
 
# Linux ELF shared library, as above, but using inflate() from zlib (libz.so)
# instead of the original UnZip version. (libz was libgz prior to 0.94)
linux_shlibz: unix_make
$(MAKE) objsdll CC=gcc AS=gcc AF="-fPIC -Di386 $(AF)" CRCA_O=crc_gcc$O\
CFLAGS="-O3 -Wall -fPIC" LOC="-DDLL -DUSE_ZLIB -DASM_CRC $(LOC)"
gcc -shared -Wl,-soname,libunzip.so.0 -o libunzip.so.0.4 $(OBJSDLL)\
crc_gcc.pic.o
ln -sf libunzip.so.0.4 libunzip.so.0
gcc -c -O unzipstb.c
gcc -o unzip unzipstb.o -L. -lunzip -lz
 
# LynxOS-x86 2.3.0 and newer, a real-time BSD-like OS; uses gcc.
lynx: unix_make
$(MAKE) unzips CC=gcc CF="$(CF) -DLynx -DLYNX -DBSD -DUNIX"
 
# Macintosh MacOS X (Unix-compatible enviroment), using standard compiler
macosx: unix_make
$(MAKE) unzips CFLAGS="-O3 -Wall -DBSD" LF2=""
$(STRIP) $(UNZIPS)
 
# Macintosh MacOS X (Unix-compatible enviroment), using gcc
macosx_gcc: unix_make
$(MAKE) unzips CC=gcc CFLAGS="-O3 -Wall -DBSD" LF2=""
$(STRIP) $(UNZIPS)
 
# Minix 1.5 PC for the 386. Invoke as is to use default cc, or as "make
# minix CC=gcc" to use gcc. Try "make linux" if you have a working termios.h.
minix: unix_make
$(MAKE) unzips CF="$(CF) -DMINIX -DSHORT_NAMES -DNO_LCHOWN -DNO_LCHMOD" CC=$(CC) LD=$(CC)
 
# MPE/iX, the Unix variant for HP 3000 systems.
mpeix: unix_make
$(MAKE) unzips CC=c89\
CF="$(CF) -DUNIX -D_POSIX_SOURCE -DHAVE_TERMIOS_H -DPASSWD_FROM_STDIN -DNO_PARAM_H -DNO_LCHOWN -DNO_LCHMOD"\
LF2=-lbsd CP=cp LN="ln -s"
 
# NeXT info.
next:
@echo
@echo\
' Please pick a specific NeXT target: "make next10" will create a generic'
@echo\
' NeXT executable; "make next2x" will create a smaller executable (for'
@echo\
' NeXTstep 2.0 and higher); "make next3x" will create a small executable'
@echo\
' with significantly better optimization (NeXTstep 3.0 and higher only);'
@echo\
' "make nextfat" will create a fat, multi-architecture (NeXT plus Intel)'
@echo\
' executable (NeXTstep 3.1 and higher only).'
@echo
 
# 68030 BSD 4.3+Mach. NeXT 2.x: make the executable smaller.
next2x: unix_make
$(MAKE) unzips LF2="-object -s"
 
# NeXT 3.x: as above, plus better optimization.
next3x: unix_make
$(MAKE) unzips CFLAGS="-O2" LF2="-object -s"
 
# NeXT 3.1+: make the executable fat (multi-architecture binary [MAB],
# for "black" [NeXT] and "white" [x86] hardware, so far).
nextfat: unix_make
$(MAKE) unzips CFLAGS="-O2 -arch i386 -arch m68k" \
LF2="-arch i386 -arch m68k -object -s"
 
# IBM OS/390 (formerly MVS) compiled under "OpenEdition" shell
os390: unix_make
set -x; \
$(MAKE) $(MAKEF) unzips \
CC=c89 LD="\$$(CC) -Wl,EDIT=NO" \
CF="$(CF) -DSYSV -DUNIX -DOS390 -DEBCDIC -DNO_PARAM_H \
-DNO_LCHOWN -DNO_LCHMOD \
-D_ALL_SOURCE $(HOST_VERSINFO)" LF2=""
 
# Sequent Symmetry running Dynix/ptx (sort of SysV.3): needs to link
# with libseq to get symlink().
ptx: unix_make
$(MAKE) unzips CF="$(CF) -DSYSV -DTERMIO -DPTX -DNO_LCHOWN -DNO_LCHMOD" LF2="$(LF2) -lseq"
 
# Pyramid 90X (probably all) under >= OSx4.1, either universe. (This is an
# experimental target! If it fails, use either pyr_ucb or pyr_att instead.)
# The make in the BSD half is too stupid to understand $(MAKE), sigh...
pyramid: unix_make
-make $(MAKEF) pyr_`universe`
 
# QNX/Neutrino is "special" because you don't have any native development
# tools yet. Set ARCH to "x86", "ppcbe", "ppcle", "mipsbe", or "mipsle"
# to produce x86, PowerPC (big- or little-endian) and MIPS (big-
# or little-endian) using gcc. [cjh]
qnxnto: unix_make
@if [ "$(ARCH)" = "" ] ; then \
echo "You didn't set ARCH; I'll assume you meant ARCH=x86..." ; \
echo "" ; \
$(MAKE) $(MAKEF) CC="qcc -Vgcc_ntox86" unzips ; \
else \
echo "Making unzip for $(ARCH)..." ; \
echo "" ; \
$(MAKE) $(MAKEF) CC="qcc -Vgcc_nto$(ARCH)" unzips ; \
fi
 
# REGULUS: 68040-based, "real-time" SysV.3 mutant; uses gcc, with "REGULUS"
# predefined.
regulus: unix_make
$(MAKE) unzips CF="$(CF) -traditional -DSYSV -DNO_MKDIR -DNO_LCHOWN -DNO_LCHMOD"
 
# IBM RS/6000 under AIX 3.2
rs6000: unix_make
$(MAKE) unzips CF="$(CF) -DBSD -D_BSD -DUNIX" LF2="-lbsd"
 
# SCO cross compile from Unix to DOS. Tested with Xenix/386 and OpenDeskTop.
# Should work with Xenix/286 as well. (davidsen) Note that you *must* remove
# the Unix objects and executable before doing this! (Piet Plomp: gcc won't
# recognize the -M0 flag that forces 8086 code.) (GRR: may need to reduce
# stack to 0c00h if using 286/small-model code...?)
sco_dos: unix_make
$(MAKE) unzips CFLAGS="-O -dos -M0" M=msdos OSDEP_H="msdos/doscfg.h" \
LF="-dos -F 2000" LF2="-o unzip.exe" \
FL="-dos" FL2="-o funzip.exe" SL="-dos" SL2="-o unzipsfx.exe"
 
# SCO UNIX with shared libraries and no international support. If you are
# not using a USA-style keyboard and display, you may want to remove -nointl
# to get support. It adds quite a bit to the size of the executable.
sco_sl: unix_make
$(MAKE) unzips LF="$(LF) -nointl" LF2="$(LF2) -lc_s"\
SL="$(SL) -nointl" FL="$(FL) -nointl"
 
# SCO Xenix/286 2.2.3 or later with development system 2.2.1 or later
sco_x286: unix_make
$(MAKE) unzips CF="$(CF) -Mel2 -LARGE -DNO_MKDIR -DNO_LCHOWN -DNO_LCHMOD" \
LF="$(LF) -Mel2 -LARGE -lx" SL="$(SL) -Mel2 -LARGE" \
FL="$(FL) -Mel2 -LARGE"
 
# Sequent Symmetry with Dynix. (386, but needs -DZMEM)
# This should also work on Balance but I can't test it just yet.
sequent: unix_make
$(MAKE) unzips CF="$(CF) -DBSD -DZMEM -DNO_LCHOWN -DNO_LCHMOD"
 
# Sun 2, 3, 4 running SunOS 3.x
sunos3: unix_make
$(MAKE) unzips CF="$(CF) -DNO_UID_GID -DUID_USHORT -DNO_LCHOWN -DNO_LCHMOD"
 
# Generic System V + GNU C
sysv_gcc: unix_make
$(MAKE) unzips CC=gcc LD=gcc CFLAGS="-O2 -DSYSV" LF2=""
$(STRIP) $(UNZIPS)
 
# AT&T 6300+, System V.2 Unix: run-time out-of-memory error if don't use -Ml;
# also compile-time error if work arrays dimensioned at HSIZE+2 (>32K)
sysv6300: unix_make
$(MAKE) unzips CF="$(CF) -Ml -DSYSV -DNO_LCHOWN -DNO_LCHMOD" LF="$(LF) -Ml"\
SL="$(SL) -Ml" FL="$(FL) -Ml"
 
# Texas Instruments System V.3 (running on HP 9000-1500)
ti_sysv: unix_make
$(MAKE) unzips CF="$(CF) -DSYSV -DNO_UID_GID -DUID_USHORT -DNO_LCHOWN -DNO_LCHMOD"
 
# SCO Xenix (Joe Foster 950508: "unzip needs to be linked with -lx [for the
# opendir(), readdir(), telldir(), rewinddir(), and closedir() calls]")
xenix: unix_make
$(MAKE) unzips LF2="$(LF2) -lx"
 
# Wombat 68000 (or whatever).
# I didn't do this. I swear. No, really.
wombat: unix_make
@echo
@echo ' Ha ha! Just kidding.'
@echo
/programs/fs/unzip60/unix/Packaging/README
0,0 → 1,44
Solaris packaging
-----------------
 
To generate a Solaris package for Info-ZIP UnZip utilities,
first see the top level INSTALL and README files. Do a
"make solaris", which will automatically build two Solaris
installable package files for the package, IZunzip.
 
IZunzip -- Solaris installable package in directory format.
IZunzip_$(arch).pkg -- Solaris installable package in "stream" format.
 
Where: $(arch) := system architecture, currently i386, sparc, or ppc.
(use "uname -p" to determine)
 
The ".pkg" file is a single file datastream that can be compressed
and/or ftp'd. This is the recommended form, because all required
files are resident in the archive, and it is easily distributed.
 
To install, simply:
 
1) copy the package to the target system's /tmp directory.
2) login or su to root
3) pkgadd -d /tmp/IZunzip_$(arch).pkg
4) add /opt/Info-ZIP/IZunzip/bin to PATH
5) add /opt/Info-ZIP/IZunzip/man to MANPATH
 
This works for both SPARC and x86.
 
Ongoing maintenance:
 
Keep the files, "prototype" and "pkginfo.in" up to date.
Observe variable substitutions made by "Makefile".
See manpages for pkginfo(1), pkginfo(4), pkgmk(1), pkgproto(1)
 
Variations:
 
If you wish the base directory to be set to something other than
/opt/Info-ZIP, change the setting BASEDIR in pkginfo.in and
re-run the make.
 
 
-John Bush (John.Bush@East.Sun.COM)
July 20, 1996
 
/programs/fs/unzip60/unix/Packaging/pkginfo.in
0,0 → 1,13
PKG=IZunzip
NAME=Info-ZIP UnZip Utilities
CATEGORY=application
VENDOR=Info-ZIP
EMAIL=Zip-Bugs@lists.wku.edu
HOTLINE=Zip-Bugs@lists.wku.edu
DESC=Copyrighted FREEWARE. See README, WHERE, and LICENSE docs in pkg's doc dir.
CLASSES=none
BASEDIR=/opt/Info-ZIP
#BASEDIR=/usr/local
VERSION=".VERSION."
PSTAMP=".PSTAMP."
ARCH=".ARCH."
/programs/fs/unzip60/unix/Packaging/postinstall
0,0 → 1,22
#!/bin/sh
#
# Post installation script (simply inform installer about PATH etc)
#
echo " "
echo " "
echo "Installation is complete. Now, you should add the following"
echo "(or equivalnet) commands to the appropriate initial user shell"
echo "scripts (such as .profile, .login, etc) -- "
echo " "
echo " For korn or bourne shell:"
echo " PATH=\${PATH}:${BASEDIR}/${PKG}/bin"
echo " MANPATH=\${MANPATH}:${BASEDIR}/${PKG}/man"
echo " export PATH MANPATH"
echo " "
echo " For C shell:"
echo " set path=(\$path ${BASEDIR}/${PKG}/bin)"
echo " setenv MANPATH \$MANPATH:${BASEDIR}/${PKG}/man"
echo " "
echo " See the files under ${BASEDIR}/${PKG}/doc for more information."
echo " "
exit 0
/programs/fs/unzip60/unix/Packaging/preinstall.in
0,0 → 1,26
#!/bin/sh
echo " "
echo "REPORT ALL BUGS, PROBLEMS, AND ACCOLADES TO:"
echo " "
echo " Zip-Bugs@lists.wku.edu"
echo " "
echo "Checking architecture platform for .ARCH. ..."
arch=`uname -p`
if [ "arch_${arch}" != "arch_.ARCH." ]; then
echo " "
echo "This product MUST be installed on a Solaris .ARCH. platform."
echo "Your machine looks like it is a ${arch} platform."
echo "Please install the version for the .ARCH. architecture."
echo "Aborting the installation because of this. "
echo " "
returncode=1
else
echo " "
echo "This product works on .ARCH., which you happen to have!"
echo " "
returncode=0
fi
echo " "
/usr/bin/sleep 4
exit ${returncode:-1}
#
/programs/fs/unzip60/unix/Packaging/prototype
0,0 → 1,33
d none $BASEDIR 0755 root bin
d none $BASEDIR/$PKG 0755 root bin
d none $PKG/bin 0755 root bin
f none $PKG/bin/unzip=unzip 0755 root bin
f none $PKG/bin/funzip=funzip 0755 root bin
f none $PKG/bin/unzipsfx=unzipsfx 0755 root bin
f none $PKG/bin/zipgrep=unix/zipgrep 0755 root bin
s none $PKG/bin/zipinfo=unzip
d none $PKG/doc 0755 root bin
f none $PKG/doc/ZipPorts=proginfo/ZipPorts 0644 root bin
f none $PKG/doc/CONTRIBS=proginfo/CONTRIBS 0644 root bin
f none $PKG/doc/COPYING.OLD=COPYING.OLD 0644 root bin
f none $PKG/doc/LICENSE=LICENSE 0644 root bin
f none $PKG/doc/README=README 0644 root bin
f none $PKG/doc/WHERE=WHERE 0644 root bin
f none $PKG/doc/INSTALL=INSTALL 0644 root bin
f none $PKG/doc/funzip.txt=funzip.txt 0644 root bin
f none $PKG/doc/unzip.txt=unzip.txt 0644 root bin
f none $PKG/doc/unzipsfx.txt=unzipsfx.txt 0644 root bin
f none $PKG/doc/zipgrep.txt=zipgrep.txt 0644 root bin
f none $PKG/doc/zipinfo.txt=zipinfo.txt 0644 root bin
d none $PKG/man 0755 root bin
d none $PKG/man/man1 0755 root bin
f none $PKG/man/man1/funzip.1=man/funzip.1 0644 root bin
f none $PKG/man/man1/unzip.1=man/unzip.1 0644 root bin
f none $PKG/man/man1/unzipsfx.1=man/unzipsfx.1 0644 root bin
f none $PKG/man/man1/zipgrep.1=man/zipgrep.1 0644 root bin
f none $PKG/man/man1/zipinfo.1=man/zipinfo.1 0644 root bin
i pkginfo
i prototype
i README
i preinstall
i postinstall
/programs/fs/unzip60/unix/configure
0,0 → 1,652
:
#!/bin/sh -x
# The above : is necessary on some buggy systems.
 
# configure: Guess values for system-dependent variables
# Output the flag definitions to the file "flags".
# Parameters: $1 = $(CC), $2 = $(CFLAGS), $3 = $(IZ_BZIP2)
# To construct unzip automatically using this file, type
# "make -f unix/Makefile generic".
# If this fails, then type "make list" to get a list of special targets.
 
trap "rm -f conftest* core a.out; exit 1" 1 2 3 15
 
CC=${1-cc}
CFLAGS=${2}
CFLAGSR=${CFLAGS}
IZ_BZIP2=${3}
CFLAGS="${CFLAGS} -I. -DUNIX"
LFLAGS1=""
LFLAGS2="-s"
LN="ln -s"
 
CFLAGS_OPT=''
CFLAGS_BZ=''
BZLF=''
 
echo "Check C compiler operation"
cat > conftest.c << _EOF_
int main()
{
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c
status=$?
if test $status -ne 0; then
echo ''
echo "C compiler \"${CC}\" does not work as expected."
echo "Failing command was: $CC $CFLAGS -c conftest.c"
exit $status
else
echo ' Ok'
fi
 
echo 'Check C compiler type (optimization options)'
# Sun C?
cat > conftest.c << _EOF_
int main()
{
#ifndef __SUNPRO_C
bad code
#endif
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c > /dev/null 2>/dev/null
if test $? -eq 0; then
CFLAGS_OPT='-xO3'
echo " Sun C ($CFLAGS_OPT)"
else
# Tru64 DEC/Compaq/HP C?
cat > conftest.c << _EOF_
int main()
{
#ifndef __DECC
bad code
#endif
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c > /dev/null 2>/dev/null
if test $? -eq 0; then
CFLAGS_OPT='-O3'
echo " DEC C ($CFLAGS_OPT)"
else
# HP-UX HP C?
cat > conftest.c << _EOF_
int main()
{
#ifdef __GNUC__
bad code
#endif
#ifndef __hpux
bad code
#endif
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c > /dev/null 2>/dev/null
if test $? -eq 0; then
# HP-UX, not GCC. Lame bundled or real ANSI compiler?
CFLAGS_OPT_TRY="+O3 +Onolimit"
$CC $CFLAGS $CFLAGS_OPT_TRY -c conftest.c 2>&1 | \
grep '(Bundled)' > /dev/null
if test $? -ne 0; then
CFLAGS_OPT="$CFLAGS_OPT_TRY"
echo " HP-UX ANSI C ($CFLAGS_OPT)"
else
echo ' HP-UX Bundled C (no opt)'
fi
else
# GNU C?
cat > conftest.c << _EOF_
int main()
{
#ifndef __GNUC__
bad code
#endif
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c > /dev/null 2>/dev/null
if test $? -eq 0; then
CFLAGS_OPT='-O3'
echo " GNU C ($CFLAGS_OPT)"
# Special Mac OS X shared library "ld" option?
if test ` uname -s 2> /dev/null ` = 'Darwin'; then
lf='-Wl,-search_paths_first'
$CC $CFLAGS $lf conftest.c > /dev/null 2>/dev/null
if test $? -eq 0; then
BZLF=${lf}
fi
rm -f conftest
fi
else
CFLAGS_OPT='-O'
echo " Other-unknown C ($CFLAGS_OPT)"
fi
fi
fi
fi
 
# optimization flags
if test -n "${CFLAGS_OPT}"; then
CFLAGSR="${CFLAGSR} ${CFLAGS_OPT}"
CFLAGS_BZ="${CFLAGS_BZ} ${CFLAGS_OPT}"
fi
 
echo Check for the C preprocessor
# on SVR4, cc -E does not produce correct assembler files. Need /lib/cpp.
CPP="${CC} -E"
# solaris as(1) needs -P, maybe others as well ?
[ -f /usr/ccs/lib/cpp ] && CPP="/usr/ccs/lib/cpp -P"
[ -f /usr/lib/cpp ] && CPP=/usr/lib/cpp
[ -f /lib/cpp ] && CPP=/lib/cpp
[ -f /usr/bin/cpp ] && CPP=/usr/bin/cpp
[ -f /xenix ] && CPP="${CC} -E"
[ -f /lynx.os ] && CPP="${CC} -E"
 
echo "#include <stdio.h>" > conftest.c
$CPP conftest.c >/dev/null 2>/dev/null || CPP="${CC} -E"
 
echo Check if we can use asm code
CRC32OA=""
if eval "$CPP crc_i386.S > _crc_i386.s 2>/dev/null"; then
if test ! -s _crc_i386.s || grep error < _crc_i386.s > /dev/null; then
:
elif eval "$CC -c _crc_i386.s >/dev/null 2>/dev/null" && [ -f _crc_i386.o ]; then
CFLAGSR="${CFLAGSR} -DASM_CRC"
CRC32OA="crc_gcc.o"
echo "int foo() { return 0;}" > conftest.c
$CC -c conftest.c >/dev/null 2>/dev/null
echo Check if compiler generates underlines
nm conftest.o | grep "(^|[^_])foo" >/dev/null 2>/dev/null
[ $? -eq 0 ] && CPP="${CPP} -DNO_UNDERLINE"
fi
fi
rm -f _crc_i386.s _crc_i386.o
 
# ANSI options for compilers that don't have __STDC__ defined by default
# Currently HPUX, pyramid, Dynix, AIX, OSF/1 and ultrix
 
echo Check for ANSI options
cat > conftest.c << _EOF_
int main()
{
#ifndef __STDC__
forget it
#endif
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c > /dev/null 2>/dev/null
if [ $? -ne 0 ]; then
for OPT in "-Aa -D_HPUX_SOURCE" -Xa -qlanglvl=ansi -std1 -std
do
$CC $CFLAGS $OPT -c conftest.c > /dev/null 2>/dev/null
[ $? -eq 0 ] && CFLAGSR="${CFLAGSR} ${OPT}" && break
done
fi
 
echo Check for prototypes
echo "int main(int argc, char *argv[]) { return 0; }" > conftest.c
$CC $CFLAGS -c conftest.c > /dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_PROTO"
 
# const check currently handles mips cc and non ANSI compilers.
# does it need more ?
echo Check the handling of const
cat > conftest.c << _EOF_
typedef int charset[2];
int main()
{
const charset x;
const char *foo;
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_CONST"
 
echo Check for time_t
cat > conftest.c << _EOF_
#include <sys/types.h>
#include <time.h>
int main()
{
time_t t;
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_TIME_T"
 
echo Check for size_t
cat > conftest.c << _EOF_
#include <sys/types.h>
int main()
{
size_t s;
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_SIZE_T"
 
echo Check for off_t
cat > conftest.c << _EOF_
#include <sys/types.h>
int main()
{
off_t s;
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_OFF_T"
 
# Added 11/4/2003 EG
# Revised 8/12/04 EG
# Now we set the 64-bit file environment and check the size of off_t
echo Check for Large File Support
cat > conftest.c << _EOF_
# define _LARGEFILE_SOURCE /* some OSes need this for fseeko */
# define _LARGEFILE64_SOURCE
# define _FILE_OFFSET_BITS 64 /* select default interface as 64 bit */
# define _LARGE_FILES /* some OSes need this for 64-bit off_t */
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
off_t offset;
struct stat s;
/* see if have 64-bit off_t */
if (sizeof(offset) < 8)
return 1;
printf(" off_t is %d bytes\n", sizeof(off_t));
/* see if have 64-bit stat */
if (sizeof(s.st_size) < 8) {
printf(" s.st_size is %d bytes\n", sizeof(s.st_size));
return 2;
}
return 3;
}
_EOF_
# compile it
$CC -o conftest conftest.c >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echo -- no Large File Support
else
# run it
./conftest
r=$?
if [ $r -eq 1 ]; then
echo -- no Large File Support - no 64-bit off_t
elif [ $r -eq 2 ]; then
echo -- no Large File Support - no 64-bit stat
elif [ $r -eq 3 ]; then
echo -- yes we have Large File Support!
CFLAGSR="${CFLAGSR} -DLARGE_FILE_SUPPORT"
else
echo -- no Large File Support - conftest returned $r
fi
fi
 
# Added 11/24/2005 EG
# Check for wide char for Unicode support
echo Check for wide char support
cat > conftest.c << _EOF_
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
int main()
{
size_t wsize;
wchar_t *wide_string;
 
if ((wide_string = (wchar_t *)malloc(4 * sizeof(wchar_t))) == NULL) {
return 0;
}
/* get wide string */
wsize = mbstowcs(wide_string, "foo", 3);
wide_string[wsize] = (wchar_t) NULL;
#ifndef __STDC_ISO_10646__
return 1;
#else
printf(" __STDC_ISO_10646__ = %d\n", __STDC_ISO_10646__);
return 2;
#endif
}
_EOF_
# compile it
$CC -o conftest conftest.c >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echo "-- no Unicode (wchar_t) support"
else
# have wide char support
# run it
./conftest
r=$?
if [ $r -eq 0 ]; then
echo -- no Unicode wchar_t support - wchar_t allocation error
elif [ $r -eq 1 ]; then
echo -- no Unicode support - wchar_t encoding unspecified
elif [ $r -eq 2 ]; then
echo -- have wchar_t with known UCS encoding - enabling Unicode support!
CFLAGSR="${CFLAGSR} -DUNICODE_SUPPORT -DUNICODE_WCHAR"
else
echo "-- no Unicode (wchar_t) support - conftest returned $r"
fi
fi
 
echo "Check for setlocale support (needed for UNICODE Native check)"
cat > conftest.c << _EOF_
#include <locale.h>
int main()
{
char *loc = setlocale(LC_CTYPE, "");
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
echo "-- have setlocale, can check for charset type"
echo "-- - enabling UTF8-native support!"
CFLAGSR="${CFLAGSR} -DUNICODE_SUPPORT -DUTF8_MAYBE_NATIVE"
else
echo "-- no Unicode (UTF-8 native) support!"
CFLAGSR="${CFLAGSR} -DNO_SETLOCALE"
fi
 
# from configure 2.4i (Onno) 12/5/04
echo Check for gcc no-builtin flag
# -fno-builtin since version 2
cat > conftest.c << _EOF_
int main()
{
#if __GNUC__ >= 2
return 0;
#else
forget it
#endif
}
_EOF_
$CC $CFLAGS -c conftest.c >/dev/null 2>/dev/null
[ $? -eq 0 ] && BFLAG="-fno-builtin"
 
# Check for missing functions
# add NO_'function_name' to flags if missing
for func in fchmod fchown lchown nl_langinfo
do
echo Check for $func
echo "int main(){ $func(); return 0; }" > conftest.c
$CC $BFLAG -o conftest conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_`echo $func | tr '[a-z]' '[A-Z]'`"
done
 
# Check (seriously) for a working lchmod.
echo 'Check for lchmod'
temp_file="/tmp/unzip_test_$$"
temp_link="link_$$"
( echo '#include <unistd.h>' ; \
echo "int main() { lchmod(\"${temp_file}\", 0666); }" \
) > conftest.c
ln -s "${temp_link}" "${temp_file}" && \
$CC $BFLAG -o conftest conftest.c >/dev/null 2>/dev/null && \
./conftest
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_LCHMOD"
rm -f "${temp_file}"
 
echo Check for memset
echo "int main(){ char k; memset(&k,0,0); return 0; }" > conftest.c
$CC -o conftest conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DZMEM"
 
echo Check for errno declaration
cat > conftest.c << _EOF_
#include <errno.h>
main()
{
errno = 0;
return 0;
}
_EOF_
$CC $CFLAGS -c conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_ERRNO"
 
echo Check for directory libraries
cat > conftest.c << _EOF_
int main() { return closedir(opendir(".")); }
_EOF_
 
$CC -o conftest conftest.c >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
OPT=""
for lib in ndir dir ucb bsd BSD PW x dirent
do
$CC -o conftest conftest.c -l$lib >/dev/null 2>/dev/null
[ $? -eq 0 ] && OPT=-l$lib && break
done
if [ ${OPT} ]; then
LFLAGS2="${LFLAGS2} ${OPT}"
else
CFLAGSR="${CFLAGSR} -DNO_DIR"
fi
fi
 
# Dynix/ptx 1.3 needed this
echo Check for readlink
echo "int main(){ return readlink(); }" > conftest.c
$CC -o conftest conftest.c >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
$CC -o conftest conftest.c -lseq >/dev/null 2>/dev/null
[ $? -eq 0 ] && LFLAGS2="${LFLAGS2} -lseq"
fi
 
echo Check for directory include file
OPT=""
for inc in dirent.h sys/ndir.h ndir.h sys/dir.h
do
echo "#include <$inc>" > conftest.c
$CPP conftest.c > /dev/null 2>/dev/null
[ $? -eq 0 ] && OPT="-DHAVE_`echo $inc | tr '[a-z]./' '[A-Z]__'`" && break
done
CFLAGSR="${CFLAGSR} ${OPT}"
 
echo Check for non existent include files
for inc in stdlib.h stddef.h unistd.h fcntl.h string.h langinfo.h
do
echo "#include <$inc>" > conftest.c
$CPP conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_`echo $inc | tr '[a-z]./' '[A-Z]__'`"
done
 
echo Check for term I/O include file
OPT=""
for inc in termios.h termio.h sgtty.h
do
echo "#include <$inc>" > conftest.c
$CPP conftest.c > /dev/null 2>/dev/null
[ $? -eq 0 ] && OPT="-DHAVE_`echo $inc | tr '[a-z]./' '[A-Z]__'`" && break
done
CFLAGSR="${CFLAGSR} ${OPT}"
 
echo Check for MBCS include files
OPT=""
for inc in mbstring.h mbctype.h
do
echo "#include <$inc>" > conftest.c
$CPP conftest.c > /dev/null 2>/dev/null
[ $? -eq 0 ] && OPT="-DHAVE_`echo $inc | tr '[a-z]./' '[A-Z]__'`" && break
done
CFLAGSR="${CFLAGSR} ${OPT}"
 
# Check for MBCS support
echo Check for MBCS support
cat > conftest.c << _EOF_
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#ifdef HAVE_MBSTRING_H
# include <mbstring.h>
#endif
int main()
{
char *tst;
tst = "Hallo";
return mblen(tst, MB_CUR_MAX);
}
_EOF_
# compile it
$CC ${CFLAGS} ${CFLAGSR} -o conftest conftest.c >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echo "-- no MBCS support"
CFLAGSR="${CFLAGSR} -DNO_MBCS"
else
#
echo "-- have MBCS support"
CFLAGSR="${CFLAGSR} -D_MBCS"
# check for library-supplied functions
# add FUNCTION_NAME='function_name' to flags if found
for func in mbschr mbsrchr
do
echo Check for MBCS $func
echo "int main() { $func(); return 0; }" > conftest.c
$CC $BFLAG -o conftest conftest.c >/dev/null 2>/dev/null
[ $? -eq 0 ] && CFLAGSR="${CFLAGSR} -D`echo $func | tr '[a-z]' '[A-Z]'`=$func"
done
fi
 
# needed for AIX (and others ?) when mmap is used
echo Check for valloc
cat > conftest.c << _EOF_
main()
{
#ifdef MMAP
valloc();
#endif
}
_EOF_
$CC ${CFLAGS} -c conftest.c > /dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGSR="${CFLAGSR} -DNO_VALLOC"
 
echo Check for /usr/local/bin and /usr/local/man
BINDIR=$HOME/bin
[ -d /usr/local/bin ] && BINDIR=/usr/local/bin
 
MANDIR=manl
[ -d /usr/man/manl ] && MANDIR=/usr/man/manl
[ -d /usr/local/man/manl ] && MANDIR=/usr/local/man/manl
[ -d /usr/local/man/man1 ] && MANDIR=/usr/local/man/man1
 
echo Checking for OS specialties
if [ -f /usr/bin/hostinfo ]; then
if /usr/bin/hostinfo | grep NeXT > /dev/null; then
CFLAGSR="${CFLAGSR} -posix"
LFLAGS1="${LFLAGS1} -posix -object"
fi
# XXX ATT6300, Cray
elif [ -f /xenix ]; then
if uname -p | grep 286 > /dev/null; then
CFLAGSR="${CFLAGSR} -LARGE -Mel2 -DMEDIUM_MEM -DWSIZE=16384 -DNO_VOID"
LFLAGS1="${LFLAGS1} -LARGE -Mel2"
fi
elif uname -X >/dev/null 2>/dev/null; then
# SCO shared library check
echo "int main() { return 0;}" > conftest.c
$CC -o conftest conftest.c -lc_s -nointl >/dev/null 2> /dev/null
[ $? -eq 0 ] && LFLAGS2="-lc_s -nointl"
else
SYSTEM=`uname -s 2>/dev/null` || SYSTEM="unknown"
echo "int main() { return 0;}" > conftest.c
case $SYSTEM in
OSF1|ULTRIX)
echo Check for -Olimit option
$CC ${CFLAGS} -Olimit 1000 -o conftest conftest.c >/dev/null 2>/dev/null
[ $? -eq 0 ] && CFLAGSR="${CFLAGSR} -Olimit 1000"
;;
### HP-UX)
### echo Check for +Onolimit option
### $CC ${CFLAGS} +Onolimit -o conftest conftest.c >/dev/null 2>/dev/null
### [ $? -eq 0 ] && CFLAGSR="${CFLAGSR} +Onolimit"
### ;;
### SunOS)
### CFLAGSR="${CFLAGSR} -D_FILE_OFFSET_BITS=64"
### ;;
esac
fi
 
echo Check for symbolic links
ln -s /dev/null null > /dev/null 2>/dev/null || LN=ln
 
rm -f a.out conftest.c conftest.o conftest null
 
 
# bzip2
 
echo "Check bzip2 support"
D_USE_BZ2=""
LIBBZ2=""
L_BZ2=""
CC_BZ="${CC}"
 
if test -n "${IZ_BZIP2}" -a "${IZ_BZIP2}" != "bzip2" ; then
echo " Check for bzip2 compiled library in IZ_BZIP2 (${IZ_BZIP2})"
if test -f "${IZ_BZIP2}/libbz2.a"; then
#
# A bzip2 library built with BZ_NO_STDIO should have an
# unresolved external, "bz_internal_error". The default,
# full-function library will not mention it.
#
nm ${IZ_BZIP2}/libbz2.a | grep bz_internal_error > /dev/null
if test $? -eq 0; then
echo " Found bzip2 BZ_NO_STDIO library, ${IZ_BZIP2}/libbz2.a"
if test -f "${IZ_BZIP2}/bzlib.h"; then
LIBBZ2="${IZ_BZIP2}/libbz2.a"
D_USE_BZ2="-DUSE_BZIP2"
L_BZ2="${BZLF} -lbz2"
echo "-- Found bzip2 library - linking in bzip2"
else
echo " ${IZ_BZIP2}/bzlib.h not found"
echo "-- Since IZ_BZIP2 defined (!= \"bzip2\"),"
echo "-- => skipping OS and bzip2 dir checks."
echo "-- NO bzip2 support !"
fi
else
echo " Found bzip2 library, ${IZ_BZIP2}/libbz2.a,"
echo " but library not compiled with BZ_NO_STDIO."
echo " ERROR: This (default) variant of bzip2 library is NOT"
echo " supported with UnZip because of its incompatible"
echo " error handling!"
echo " Please see the UnZip installation instructions in"
echo " the INSTALL text file."
echo " Skipping bzip2 support..."
fi
else
echo " ${IZ_BZIP2}/libbz2.a not found"
echo "-- Since IZ_BZIP2 defined (!= \"bzip2\"),"
echo "-- => skipping OS and bzip2 dir checks."
echo "-- NO bzip2 support !"
fi
else
echo " Check for bzip2 sources in unzip's bzip2 subdirectory"
if test -f "${IZ_BZIP2}/bzlib.c" -a -f "${IZ_BZIP2}/bzlib.h"; then
echo "-- Found bzip2 source in ${IZ_BZIP2}/ directory"
echo "-- Will try to build bzip2 library from source and link in"
LIBBZ2="${IZ_BZIP2}/libbz2.a"
D_USE_BZ2="-DUSE_BZIP2"
L_BZ2="${BZLF} -lbz2"
else
echo "-- bzip2 sources not found - no bzip2 support"
fi
fi
 
 
echo CC=\"${CC}\" CF=\"${CFLAGSR} ${D_USE_BZ2}\" CRCA_O=\"${CRC32OA}\" \
AS=\"${CC} -c\" LFLAGS1=\"${LFLAGS1}\" LF2=\"${LFLAGS2}\" \
CC_BZ=\"${CC_BZ}\" CFLAGS_BZ=\"${CFLAGS_BZ}\" \
IZ_BZIP2=\"${IZ_BZIP2}\" D_USE_BZ2=\"${D_USE_BZ2}\" \
L_BZ2=\"${L_BZ2}\" LIBBZ2=\"${LIBBZ2}\" > flags
/programs/fs/unzip60/unix/unix.c
0,0 → 1,1876
/*
Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2009-Jan-02 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*---------------------------------------------------------------------------
 
unix.c
 
Unix-specific routines for use with Info-ZIP's UnZip 5.41 and later.
 
Contains: readdir()
do_wild() <-- generic enough to put in fileio.c?
mapattr()
mapname()
checkdir()
mkdir()
close_outfile()
defer_dir_attribs()
set_direc_attribs()
stamp_file()
version()
 
---------------------------------------------------------------------------*/
 
 
#define UNZIP_INTERNAL
#include "unzip.h"
 
#ifdef SCO_XENIX
# define SYSNDIR
#else /* SCO Unix, AIX, DNIX, TI SysV, Coherent 4.x, ... */
# if defined(__convexc__) || defined(SYSV) || defined(CRAY) || defined(BSD4_4)
# define DIRENT
# endif
#endif
#if defined(_AIX) || defined(__mpexl)
# define DIRENT
#endif
#ifdef COHERENT
# if defined(_I386) || (defined(__COHERENT__) && (__COHERENT__ >= 0x420))
# define DIRENT
# endif
#endif
 
#ifdef _POSIX_VERSION
# ifndef DIRENT
# define DIRENT
# endif
#endif
 
#ifdef DIRENT
# include <dirent.h>
#else
# ifdef SYSV
# ifdef SYSNDIR
# include <sys/ndir.h>
# else
# include <ndir.h>
# endif
# else /* !SYSV */
# ifndef NO_SYSDIR
# include <sys/dir.h>
# endif
# endif /* ?SYSV */
# ifndef dirent
# define dirent direct
# endif
#endif /* ?DIRENT */
 
#ifdef SET_DIR_ATTRIB
typedef struct uxdirattr { /* struct for holding unix style directory */
struct uxdirattr *next; /* info until can be sorted and set at end */
char *fn; /* filename of directory */
union {
iztimes t3; /* mtime, atime, ctime */
ztimbuf t2; /* modtime, actime */
} u;
unsigned perms; /* same as min_info.file_attr */
int have_uidgid; /* flag */
ulg uidgid[2];
char fnbuf[1]; /* buffer stub for directory name */
} uxdirattr;
#define UxAtt(d) ((uxdirattr *)d) /* typecast shortcut */
#endif /* SET_DIR_ATTRIB */
 
#ifdef ACORN_FTYPE_NFS
/* Acorn bits for NFS filetyping */
typedef struct {
uch ID[2];
uch size[2];
uch ID_2[4];
uch loadaddr[4];
uch execaddr[4];
uch attr[4];
} RO_extra_block;
 
#endif /* ACORN_FTYPE_NFS */
 
/* static int created_dir; */ /* used in mapname(), checkdir() */
/* static int renamed_fullpath; */ /* ditto */
 
static unsigned filtattr OF((__GPRO__ unsigned perms));
 
 
/*****************************/
/* Strings used multiple */
/* times in unix.c */
/*****************************/
 
#ifndef MTS
/* messages of code for setting file/directory attributes */
static ZCONST char CannotSetItemUidGid[] =
"warning: cannot set UID %lu and/or GID %lu for %s\n %s\n";
static ZCONST char CannotSetUidGid[] =
" (warning) cannot set UID %lu and/or GID %lu\n %s";
static ZCONST char CannotSetItemTimestamps[] =
"warning: cannot set modif./access times for %s\n %s\n";
static ZCONST char CannotSetTimestamps[] =
" (warning) cannot set modif./access times\n %s";
#endif /* !MTS */
 
 
#ifndef SFX
#ifdef NO_DIR /* for AT&T 3B1 */
 
#define opendir(path) fopen(path,"r")
#define closedir(dir) fclose(dir)
typedef FILE DIR;
typedef struct zdir {
FILE *dirhandle;
struct dirent *entry;
} DIR
DIR *opendir OF((ZCONST char *dirspec));
void closedir OF((DIR *dirp));
struct dirent *readdir OF((DIR *dirp));
 
DIR *opendir(dirspec)
ZCONST char *dirspec;
{
DIR *dirp;
 
if ((dirp = malloc(sizeof(DIR)) != NULL) {
if ((dirp->dirhandle = fopen(dirspec, "r")) == NULL) {
free(dirp);
dirp = NULL;
}
}
return dirp;
}
 
void closedir(dirp)
DIR *dirp;
{
fclose(dirp->dirhandle);
free(dirp);
}
 
/*
* Apparently originally by Rich Salz.
* Cleaned up and modified by James W. Birdsall.
*/
struct dirent *readdir(dirp)
DIR *dirp;
{
 
if (dirp == NULL)
return NULL;
 
for (;;)
if (fread(&(dirp->entry), sizeof (struct dirent), 1,
dirp->dirhandle) == 0)
return (struct dirent *)NULL;
else if ((dirp->entry).d_ino)
return &(dirp->entry);
 
} /* end function readdir() */
 
#endif /* NO_DIR */
 
 
/**********************/
/* Function do_wild() */ /* for porting: dir separator; match(ignore_case) */
/**********************/
 
char *do_wild(__G__ wildspec)
__GDEF
ZCONST char *wildspec; /* only used first time on a given dir */
{
/* these statics are now declared in SYSTEM_SPECIFIC_GLOBALS in unxcfg.h:
static DIR *wild_dir = (DIR *)NULL;
static ZCONST char *wildname;
static char *dirname, matchname[FILNAMSIZ];
static int notfirstcall=FALSE, have_dirname, dirnamelen;
*/
struct dirent *file;
 
/* Even when we're just returning wildspec, we *always* do so in
* matchname[]--calling routine is allowed to append four characters
* to the returned string, and wildspec may be a pointer to argv[].
*/
if (!G.notfirstcall) { /* first call: must initialize everything */
G.notfirstcall = TRUE;
 
if (!iswild(wildspec)) {
strncpy(G.matchname, wildspec, FILNAMSIZ);
G.matchname[FILNAMSIZ-1] = '\0';
G.have_dirname = FALSE;
G.wild_dir = NULL;
return G.matchname;
}
 
/* break the wildspec into a directory part and a wildcard filename */
if ((G.wildname = (ZCONST char *)strrchr(wildspec, '/')) == NULL) {
G.dirname = ".";
G.dirnamelen = 1;
G.have_dirname = FALSE;
G.wildname = wildspec;
} else {
++G.wildname; /* point at character after '/' */
G.dirnamelen = G.wildname - wildspec;
if ((G.dirname = (char *)malloc(G.dirnamelen+1)) == (char *)NULL) {
Info(slide, 0x201, ((char *)slide,
"warning: cannot allocate wildcard buffers\n"));
strncpy(G.matchname, wildspec, FILNAMSIZ);
G.matchname[FILNAMSIZ-1] = '\0';
return G.matchname; /* but maybe filespec was not a wildcard */
}
strncpy(G.dirname, wildspec, G.dirnamelen);
G.dirname[G.dirnamelen] = '\0'; /* terminate for strcpy below */
G.have_dirname = TRUE;
}
 
if ((G.wild_dir = (zvoid *)opendir(G.dirname)) != (zvoid *)NULL) {
while ((file = readdir((DIR *)G.wild_dir)) !=
(struct dirent *)NULL) {
Trace((stderr, "do_wild: readdir returns %s\n",
FnFilter1(file->d_name)));
if (file->d_name[0] == '.' && G.wildname[0] != '.')
continue; /* Unix: '*' and '?' do not match leading dot */
if (match(file->d_name, G.wildname, 0 WISEP) &&/*0=case sens.*/
/* skip "." and ".." directory entries */
strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) {
Trace((stderr, "do_wild: match() succeeds\n"));
if (G.have_dirname) {
strcpy(G.matchname, G.dirname);
strcpy(G.matchname+G.dirnamelen, file->d_name);
} else
strcpy(G.matchname, file->d_name);
return G.matchname;
}
}
/* if we get to here directory is exhausted, so close it */
closedir((DIR *)G.wild_dir);
G.wild_dir = (zvoid *)NULL;
}
Trace((stderr, "do_wild: opendir(%s) returns NULL\n",
FnFilter1(G.dirname)));
 
/* return the raw wildspec in case that works (e.g., directory not
* searchable, but filespec was not wild and file is readable) */
strncpy(G.matchname, wildspec, FILNAMSIZ);
G.matchname[FILNAMSIZ-1] = '\0';
return G.matchname;
}
 
/* last time through, might have failed opendir but returned raw wildspec */
if ((DIR *)G.wild_dir == (DIR *)NULL) {
G.notfirstcall = FALSE; /* nothing left--reset for new wildspec */
if (G.have_dirname)
free(G.dirname);
return (char *)NULL;
}
 
/* If we've gotten this far, we've read and matched at least one entry
* successfully (in a previous call), so dirname has been copied into
* matchname already.
*/
while ((file = readdir((DIR *)G.wild_dir)) != (struct dirent *)NULL) {
Trace((stderr, "do_wild: readdir returns %s\n",
FnFilter1(file->d_name)));
if (file->d_name[0] == '.' && G.wildname[0] != '.')
continue; /* Unix: '*' and '?' do not match leading dot */
if (match(file->d_name, G.wildname, 0 WISEP)) { /* 0 == case sens. */
Trace((stderr, "do_wild: match() succeeds\n"));
if (G.have_dirname) {
/* strcpy(G.matchname, G.dirname); */
strcpy(G.matchname+G.dirnamelen, file->d_name);
} else
strcpy(G.matchname, file->d_name);
return G.matchname;
}
}
 
closedir((DIR *)G.wild_dir); /* at least one entry read; nothing left */
G.wild_dir = (zvoid *)NULL;
G.notfirstcall = FALSE; /* reset for new wildspec */
if (G.have_dirname)
free(G.dirname);
return (char *)NULL;
 
} /* end function do_wild() */
 
#endif /* !SFX */
 
 
 
 
#ifndef S_ISUID
# define S_ISUID 0004000 /* set user id on execution */
#endif
#ifndef S_ISGID
# define S_ISGID 0002000 /* set group id on execution */
#endif
#ifndef S_ISVTX
# define S_ISVTX 0001000 /* save swapped text even after use */
#endif
 
/************************/
/* Function filtattr() */
/************************/
/* This is used to clear or keep the SUID and SGID bits on file permissions.
* It's possible that a file in an archive could have one of these bits set
* and, unknown to the person unzipping, could allow others to execute the
* file as the user or group. The new option -K bypasses this check.
*/
 
static unsigned filtattr(__G__ perms)
__GDEF
unsigned perms;
{
/* keep setuid/setgid/tacky perms? */
if (!uO.K_flag)
perms &= ~(S_ISUID | S_ISGID | S_ISVTX);
 
return (0xffff & perms);
} /* end function filtattr() */
 
 
 
 
 
/**********************/
/* Function mapattr() */
/**********************/
 
int mapattr(__G)
__GDEF
{
int r;
ulg tmp = G.crec.external_file_attributes;
 
G.pInfo->file_attr = 0;
/* initialized to 0 for check in "default" branch below... */
 
switch (G.pInfo->hostnum) {
case AMIGA_:
tmp = (unsigned)(tmp>>17 & 7); /* Amiga RWE bits */
G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
break;
case THEOS_:
tmp &= 0xF1FFFFFFL;
if ((tmp & 0xF0000000L) != 0x40000000L)
tmp &= 0x01FFFFFFL; /* not a dir, mask all ftype bits */
else
tmp &= 0x41FFFFFFL; /* leave directory bit as set */
/* fall through! */
case UNIX_:
case VMS_:
case ACORN_:
case ATARI_:
case ATHEOS_:
case BEOS_:
case QDOS_:
case TANDEM_:
r = FALSE;
G.pInfo->file_attr = (unsigned)(tmp >> 16);
if (G.pInfo->file_attr == 0 && G.extra_field) {
/* Some (non-Info-ZIP) implementations of Zip for Unix and
* VMS (and probably others ??) leave 0 in the upper 16-bit
* part of the external_file_attributes field. Instead, they
* store file permission attributes in some extra field.
* As a work-around, we search for the presence of one of
* these extra fields and fall back to the MSDOS compatible
* part of external_file_attributes if one of the known
* e.f. types has been detected.
* Later, we might implement extraction of the permission
* bits from the VMS extra field. But for now, the work-around
* should be sufficient to provide "readable" extracted files.
* (For ASI Unix e.f., an experimental remap of the e.f.
* mode value IS already provided!)
*/
ush ebID;
unsigned ebLen;
uch *ef = G.extra_field;
unsigned ef_len = G.crec.extra_field_length;
 
while (!r && ef_len >= EB_HEADSIZE) {
ebID = makeword(ef);
ebLen = (unsigned)makeword(ef+EB_LEN);
if (ebLen > (ef_len - EB_HEADSIZE))
/* discoverd some e.f. inconsistency! */
break;
switch (ebID) {
case EF_ASIUNIX:
if (ebLen >= (EB_ASI_MODE+2)) {
G.pInfo->file_attr =
(unsigned)makeword(ef+(EB_HEADSIZE+EB_ASI_MODE));
/* force stop of loop: */
ef_len = (ebLen + EB_HEADSIZE);
break;
}
/* else: fall through! */
case EF_PKVMS:
/* "found nondecypherable e.f. with perm. attr" */
r = TRUE;
default:
break;
}
ef_len -= (ebLen + EB_HEADSIZE);
ef += (ebLen + EB_HEADSIZE);
}
}
if (!r) {
#ifdef SYMLINKS
/* Check if the file is a (POSIX-compatible) symbolic link.
* We restrict symlink support to those "made-by" hosts that
* are known to support symbolic links.
*/
G.pInfo->symlink = S_ISLNK(G.pInfo->file_attr) &&
SYMLINK_HOST(G.pInfo->hostnum);
#endif
return 0;
}
/* fall through! */
/* all remaining cases: expand MSDOS read-only bit into write perms */
case FS_FAT_:
/* PKWARE's PKZip for Unix marks entries as FS_FAT_, but stores the
* Unix attributes in the upper 16 bits of the external attributes
* field, just like Info-ZIP's Zip for Unix. We try to use that
* value, after a check for consistency with the MSDOS attribute
* bits (see below).
*/
G.pInfo->file_attr = (unsigned)(tmp >> 16);
/* fall through! */
case FS_HPFS_:
case FS_NTFS_:
case MAC_:
case TOPS20_:
default:
/* Ensure that DOS subdir bit is set when the entry's name ends
* in a '/'. Some third-party Zip programs fail to set the subdir
* bit for directory entries.
*/
if ((tmp & 0x10) == 0) {
extent fnlen = strlen(G.filename);
if (fnlen > 0 && G.filename[fnlen-1] == '/')
tmp |= 0x10;
}
/* read-only bit --> write perms; subdir bit --> dir exec bit */
tmp = !(tmp & 1) << 1 | (tmp & 0x10) >> 4;
if ((G.pInfo->file_attr & 0700) == (unsigned)(0400 | tmp<<6)) {
/* keep previous G.pInfo->file_attr setting, when its "owner"
* part appears to be consistent with DOS attribute flags!
*/
#ifdef SYMLINKS
/* Entries "made by FS_FAT_" could have been zipped on a
* system that supports POSIX-style symbolic links.
*/
G.pInfo->symlink = S_ISLNK(G.pInfo->file_attr) &&
(G.pInfo->hostnum == FS_FAT_);
#endif
return 0;
}
G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
break;
} /* end switch (host-OS-created-by) */
 
/* for originating systems with no concept of "group," "other," "system": */
umask( (int)(tmp=umask(0)) ); /* apply mask to expanded r/w(/x) perms */
G.pInfo->file_attr &= ~tmp;
 
return 0;
 
} /* end function mapattr() */
 
 
 
 
 
/************************/
/* Function mapname() */
/************************/
 
int mapname(__G__ renamed)
__GDEF
int renamed;
/*
* returns:
* MPN_OK - no problem detected
* MPN_INF_TRUNC - caution (truncated filename)
* MPN_INF_SKIP - info "skip entry" (dir doesn't exist)
* MPN_ERR_SKIP - error -> skip entry
* MPN_ERR_TOOLONG - error -> path is too long
* MPN_NOMEM - error (memory allocation failed) -> skip entry
* [also MPN_VOL_LABEL, MPN_CREATED_DIR]
*/
{
char pathcomp[FILNAMSIZ]; /* path-component buffer */
char *pp, *cp=(char *)NULL; /* character pointers */
char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
#ifdef ACORN_FTYPE_NFS
char *lastcomma=(char *)NULL; /* pointer to last comma in pathcomp */
RO_extra_block *ef_spark; /* pointer Acorn FTYPE ef block */
#endif
int killed_ddot = FALSE; /* is set when skipping "../" pathcomp */
int error = MPN_OK;
register unsigned workch; /* hold the character being tested */
 
 
/*---------------------------------------------------------------------------
Initialize various pointers and counters and stuff.
---------------------------------------------------------------------------*/
 
if (G.pInfo->vollabel)
return MPN_VOL_LABEL; /* can't set disk volume labels in Unix */
 
/* can create path as long as not just freshening, or if user told us */
G.create_dirs = (!uO.fflag || renamed);
 
G.created_dir = FALSE; /* not yet */
 
/* user gave full pathname: don't prepend rootpath */
G.renamed_fullpath = (renamed && (*G.filename == '/'));
 
if (checkdir(__G__ (char *)NULL, INIT) == MPN_NOMEM)
return MPN_NOMEM; /* initialize path buffer, unless no memory */
 
*pathcomp = '\0'; /* initialize translation buffer */
pp = pathcomp; /* point to translation buffer */
if (uO.jflag) /* junking directories */
cp = (char *)strrchr(G.filename, '/');
if (cp == (char *)NULL) /* no '/' or not junking dirs */
cp = G.filename; /* point to internal zipfile-member pathname */
else
++cp; /* point to start of last component of path */
 
/*---------------------------------------------------------------------------
Begin main loop through characters in filename.
---------------------------------------------------------------------------*/
 
while ((workch = (uch)*cp++) != 0) {
 
switch (workch) {
case '/': /* can assume -j flag not given */
*pp = '\0';
if (strcmp(pathcomp, ".") == 0) {
/* don't bother appending "./" to the path */
*pathcomp = '\0';
} else if (!uO.ddotflag && strcmp(pathcomp, "..") == 0) {
/* "../" dir traversal detected, skip over it */
*pathcomp = '\0';
killed_ddot = TRUE; /* set "show message" flag */
}
/* when path component is not empty, append it now */
if (*pathcomp != '\0' &&
((error = checkdir(__G__ pathcomp, APPEND_DIR))
& MPN_MASK) > MPN_INF_TRUNC)
return error;
pp = pathcomp; /* reset conversion buffer for next piece */
lastsemi = (char *)NULL; /* leave direct. semi-colons alone */
break;
 
#ifdef __CYGWIN__ /* Cygwin runs on Win32, apply FAT/NTFS filename rules */
case ':': /* drive spec not stored, so no colon allowed */
case '\\': /* '\\' may come as normal filename char (not */
case '<': /* dir sep char!) from unix-like file system */
case '>': /* no redirection symbols allowed either */
case '|': /* no pipe signs allowed */
case '"': /* no double quotes allowed */
case '?': /* no wildcards allowed */
case '*':
*pp++ = '_'; /* these rules apply equally to FAT and NTFS */
break;
#endif
 
case ';': /* VMS version (or DEC-20 attrib?) */
lastsemi = pp;
*pp++ = ';'; /* keep for now; remove VMS ";##" */
break; /* later, if requested */
 
#ifdef ACORN_FTYPE_NFS
case ',': /* NFS filetype extension */
lastcomma = pp;
*pp++ = ','; /* keep for now; may need to remove */
break; /* later, if requested */
#endif
 
#ifdef MTS
case ' ': /* change spaces to underscore under */
*pp++ = '_'; /* MTS; leave as spaces under Unix */
break;
#endif
 
default:
/* disable control character filter when requested,
* else allow 8-bit characters (e.g. UTF-8) in filenames:
*/
if (uO.cflxflag ||
(isprint(workch) || (128 <= workch && workch <= 254)))
*pp++ = (char)workch;
} /* end switch */
 
} /* end while loop */
 
/* Show warning when stripping insecure "parent dir" path components */
if (killed_ddot && QCOND2) {
Info(slide, 0, ((char *)slide,
"warning: skipped \"../\" path component(s) in %s\n",
FnFilter1(G.filename)));
if (!(error & ~MPN_MASK))
error = (error & MPN_MASK) | PK_WARN;
}
 
/*---------------------------------------------------------------------------
Report if directory was created (and no file to create: filename ended
in '/'), check name to be sure it exists, and combine path and name be-
fore exiting.
---------------------------------------------------------------------------*/
 
if (G.filename[strlen(G.filename) - 1] == '/') {
checkdir(__G__ G.filename, GETPATH);
if (G.created_dir) {
if (QCOND2) {
Info(slide, 0, ((char *)slide, " creating: %s\n",
FnFilter1(G.filename)));
}
#ifndef NO_CHMOD
/* Filter out security-relevant attributes bits. */
G.pInfo->file_attr = filtattr(__G__ G.pInfo->file_attr);
/* When extracting non-UNIX directories or when extracting
* without UID/GID restoration or SGID preservation, any
* SGID flag inherited from the parent directory should be
* maintained to allow files extracted into this new folder
* to inherit the GID setting from the parent directory.
*/
if (G.pInfo->hostnum != UNIX_ || !(uO.X_flag || uO.K_flag)) {
/* preserve SGID bit when inherited from parent dir */
if (!SSTAT(G.filename, &G.statbuf)) {
G.pInfo->file_attr |= G.statbuf.st_mode & S_ISGID;
} else {
perror("Could not read directory attributes");
}
}
 
/* set approx. dir perms (make sure can still read/write in dir) */
if (chmod(G.filename, G.pInfo->file_attr | 0700))
perror("chmod (directory attributes) error");
#endif
/* set dir time (note trailing '/') */
return (error & ~MPN_MASK) | MPN_CREATED_DIR;
}
/* dir existed already; don't look for data to extract */
return (error & ~MPN_MASK) | MPN_INF_SKIP;
}
 
*pp = '\0'; /* done with pathcomp: terminate it */
 
/* if not saving them, remove VMS version numbers (appended ";###") */
if (!uO.V_flag && lastsemi) {
pp = lastsemi + 1;
while (isdigit((uch)(*pp)))
++pp;
if (*pp == '\0') /* only digits between ';' and end: nuke */
*lastsemi = '\0';
}
 
/* On UNIX (and compatible systems), "." and ".." are reserved for
* directory navigation and cannot be used as regular file names.
* These reserved one-dot and two-dot names are mapped to "_" and "__".
*/
if (strcmp(pathcomp, ".") == 0)
*pathcomp = '_';
else if (strcmp(pathcomp, "..") == 0)
strcpy(pathcomp, "__");
 
#ifdef ACORN_FTYPE_NFS
/* translate Acorn filetype information if asked to do so */
if (uO.acorn_nfs_ext &&
(ef_spark = (RO_extra_block *)
getRISCOSexfield(G.extra_field, G.lrec.extra_field_length))
!= (RO_extra_block *)NULL)
{
/* file *must* have a RISC OS extra field */
long ft = (long)makelong(ef_spark->loadaddr);
/*32-bit*/
if (lastcomma) {
pp = lastcomma + 1;
while (isxdigit((uch)(*pp))) ++pp;
if (pp == lastcomma+4 && *pp == '\0') *lastcomma='\0'; /* nuke */
}
if ((ft & 1<<31)==0) ft=0x000FFD00;
sprintf(pathcomp+strlen(pathcomp), ",%03x", (int)(ft>>8) & 0xFFF);
}
#endif /* ACORN_FTYPE_NFS */
 
if (*pathcomp == '\0') {
Info(slide, 1, ((char *)slide, "mapname: conversion of %s failed\n",
FnFilter1(G.filename)));
return (error & ~MPN_MASK) | MPN_ERR_SKIP;
}
 
checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
checkdir(__G__ G.filename, GETPATH);
 
return error;
 
} /* end function mapname() */
 
 
 
 
#if 0 /*========== NOTES ==========*/
 
extract-to dir: a:path/
buildpath: path1/path2/ ... (NULL-terminated)
pathcomp: filename
 
mapname():
loop over chars in zipfile member name
checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
(d:/tmp/unzip/) (disk:[tmp.unzip.)
(d:/tmp/unzip/jj/) (disk:[tmp.unzip.jj.)
(d:/tmp/unzip/jj/temp/) (disk:[tmp.unzip.jj.temp.)
finally add filename itself and check for existence? (could use with rename)
(d:/tmp/unzip/jj/temp/msg.outdir) (disk:[tmp.unzip.jj.temp]msg.outdir)
checkdir(name, GETPATH) --> copy path to name and free space
 
#endif /* 0 */
 
 
 
 
/***********************/
/* Function checkdir() */
/***********************/
 
int checkdir(__G__ pathcomp, flag)
__GDEF
char *pathcomp;
int flag;
/*
* returns:
* MPN_OK - no problem detected
* MPN_INF_TRUNC - (on APPEND_NAME) truncated filename
* MPN_INF_SKIP - path doesn't exist, not allowed to create
* MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path
* exists and is not a directory, but is supposed to be
* MPN_ERR_TOOLONG - path is too long
* MPN_NOMEM - can't allocate memory for filename buffers
*/
{
/* static int rootlen = 0; */ /* length of rootpath */
/* static char *rootpath; */ /* user's "extract-to" directory */
/* static char *buildpath; */ /* full path (so far) to extracted file */
/* static char *end; */ /* pointer to end of buildpath ('\0') */
 
# define FN_MASK 7
# define FUNCTION (flag & FN_MASK)
 
 
 
/*---------------------------------------------------------------------------
APPEND_DIR: append the path component to the path being built and check
for its existence. If doesn't exist and we are creating directories, do
so for this one; else signal success or error as appropriate.
---------------------------------------------------------------------------*/
 
if (FUNCTION == APPEND_DIR) {
int too_long = FALSE;
#ifdef SHORT_NAMES
char *old_end = end;
#endif
 
Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp)));
while ((*G.end = *pathcomp++) != '\0')
++G.end;
#ifdef SHORT_NAMES /* path components restricted to 14 chars, typically */
if ((G.end-old_end) > FILENAME_MAX) /* GRR: proper constant? */
*(G.end = old_end + FILENAME_MAX) = '\0';
#endif
 
/* GRR: could do better check, see if overrunning buffer as we go:
* check end-buildpath after each append, set warning variable if
* within 20 of FILNAMSIZ; then if var set, do careful check when
* appending. Clear variable when begin new path. */
 
/* next check: need to append '/', at least one-char name, '\0' */
if ((G.end-G.buildpath) > FILNAMSIZ-3)
too_long = TRUE; /* check if extracting dir? */
if (SSTAT(G.buildpath, &G.statbuf)) { /* path doesn't exist */
if (!G.create_dirs) { /* told not to create (freshening) */
free(G.buildpath);
return MPN_INF_SKIP; /* path doesn't exist: nothing to do */
}
if (too_long) {
Info(slide, 1, ((char *)slide,
"checkdir error: path too long: %s\n",
FnFilter1(G.buildpath)));
free(G.buildpath);
/* no room for filenames: fatal */
return MPN_ERR_TOOLONG;
}
if (mkdir(G.buildpath, 0777) == -1) { /* create the directory */
Info(slide, 1, ((char *)slide,
"checkdir error: cannot create %s\n\
%s\n\
unable to process %s.\n",
FnFilter2(G.buildpath),
strerror(errno),
FnFilter1(G.filename)));
free(G.buildpath);
/* path didn't exist, tried to create, failed */
return MPN_ERR_SKIP;
}
G.created_dir = TRUE;
} else if (!S_ISDIR(G.statbuf.st_mode)) {
Info(slide, 1, ((char *)slide,
"checkdir error: %s exists but is not directory\n\
unable to process %s.\n",
FnFilter2(G.buildpath), FnFilter1(G.filename)));
free(G.buildpath);
/* path existed but wasn't dir */
return MPN_ERR_SKIP;
}
if (too_long) {
Info(slide, 1, ((char *)slide,
"checkdir error: path too long: %s\n", FnFilter1(G.buildpath)));
free(G.buildpath);
/* no room for filenames: fatal */
return MPN_ERR_TOOLONG;
}
*G.end++ = '/';
*G.end = '\0';
Trace((stderr, "buildpath now = [%s]\n", FnFilter1(G.buildpath)));
return MPN_OK;
 
} /* end if (FUNCTION == APPEND_DIR) */
 
/*---------------------------------------------------------------------------
GETPATH: copy full path to the string pointed at by pathcomp, and free
G.buildpath.
---------------------------------------------------------------------------*/
 
if (FUNCTION == GETPATH) {
strcpy(pathcomp, G.buildpath);
Trace((stderr, "getting and freeing path [%s]\n",
FnFilter1(pathcomp)));
free(G.buildpath);
G.buildpath = G.end = (char *)NULL;
return MPN_OK;
}
 
/*---------------------------------------------------------------------------
APPEND_NAME: assume the path component is the filename; append it and
return without checking for existence.
---------------------------------------------------------------------------*/
 
if (FUNCTION == APPEND_NAME) {
#ifdef SHORT_NAMES
char *old_end = end;
#endif
 
Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp)));
while ((*G.end = *pathcomp++) != '\0') {
++G.end;
#ifdef SHORT_NAMES /* truncate name at 14 characters, typically */
if ((G.end-old_end) > FILENAME_MAX) /* GRR: proper constant? */
*(G.end = old_end + FILENAME_MAX) = '\0';
#endif
if ((G.end-G.buildpath) >= FILNAMSIZ) {
*--G.end = '\0';
Info(slide, 0x201, ((char *)slide,
"checkdir warning: path too long; truncating\n\
%s\n -> %s\n",
FnFilter1(G.filename), FnFilter2(G.buildpath)));
return MPN_INF_TRUNC; /* filename truncated */
}
}
Trace((stderr, "buildpath now = [%s]\n", FnFilter1(G.buildpath)));
/* could check for existence here, prompt for new name... */
return MPN_OK;
}
 
/*---------------------------------------------------------------------------
INIT: allocate and initialize buffer space for the file currently being
extracted. If file was renamed with an absolute path, don't prepend the
extract-to path.
---------------------------------------------------------------------------*/
 
/* GRR: for VMS and TOPS-20, add up to 13 to strlen */
 
if (FUNCTION == INIT) {
Trace((stderr, "initializing buildpath to "));
#ifdef ACORN_FTYPE_NFS
if ((G.buildpath = (char *)malloc(strlen(G.filename)+G.rootlen+
(uO.acorn_nfs_ext ? 5 : 1)))
#else
if ((G.buildpath = (char *)malloc(strlen(G.filename)+G.rootlen+1))
#endif
== (char *)NULL)
return MPN_NOMEM;
if ((G.rootlen > 0) && !G.renamed_fullpath) {
strcpy(G.buildpath, G.rootpath);
G.end = G.buildpath + G.rootlen;
} else {
*G.buildpath = '\0';
G.end = G.buildpath;
}
Trace((stderr, "[%s]\n", FnFilter1(G.buildpath)));
return MPN_OK;
}
 
/*---------------------------------------------------------------------------
ROOT: if appropriate, store the path in rootpath and create it if
necessary; else assume it's a zipfile member and return. This path
segment gets used in extracting all members from every zipfile specified
on the command line.
---------------------------------------------------------------------------*/
 
#if (!defined(SFX) || defined(SFX_EXDIR))
if (FUNCTION == ROOT) {
Trace((stderr, "initializing root path to [%s]\n",
FnFilter1(pathcomp)));
if (pathcomp == (char *)NULL) {
G.rootlen = 0;
return MPN_OK;
}
if (G.rootlen > 0) /* rootpath was already set, nothing to do */
return MPN_OK;
if ((G.rootlen = strlen(pathcomp)) > 0) {
char *tmproot;
 
if ((tmproot = (char *)malloc(G.rootlen+2)) == (char *)NULL) {
G.rootlen = 0;
return MPN_NOMEM;
}
strcpy(tmproot, pathcomp);
if (tmproot[G.rootlen-1] == '/') {
tmproot[--G.rootlen] = '\0';
}
if (G.rootlen > 0 && (SSTAT(tmproot, &G.statbuf) ||
!S_ISDIR(G.statbuf.st_mode)))
{ /* path does not exist */
if (!G.create_dirs /* || iswild(tmproot) */ ) {
free(tmproot);
G.rootlen = 0;
/* skip (or treat as stored file) */
return MPN_INF_SKIP;
}
/* create the directory (could add loop here scanning tmproot
* to create more than one level, but why really necessary?) */
if (mkdir(tmproot, 0777) == -1) {
Info(slide, 1, ((char *)slide,
"checkdir: cannot create extraction directory: %s\n\
%s\n",
FnFilter1(tmproot), strerror(errno)));
free(tmproot);
G.rootlen = 0;
/* path didn't exist, tried to create, and failed: */
/* file exists, or 2+ subdir levels required */
return MPN_ERR_SKIP;
}
}
tmproot[G.rootlen++] = '/';
tmproot[G.rootlen] = '\0';
if ((G.rootpath = (char *)realloc(tmproot, G.rootlen+1)) == NULL) {
free(tmproot);
G.rootlen = 0;
return MPN_NOMEM;
}
Trace((stderr, "rootpath now = [%s]\n", FnFilter1(G.rootpath)));
}
return MPN_OK;
}
#endif /* !SFX || SFX_EXDIR */
 
/*---------------------------------------------------------------------------
END: free rootpath, immediately prior to program exit.
---------------------------------------------------------------------------*/
 
if (FUNCTION == END) {
Trace((stderr, "freeing rootpath\n"));
if (G.rootlen > 0) {
free(G.rootpath);
G.rootlen = 0;
}
return MPN_OK;
}
 
return MPN_INVALID; /* should never reach */
 
} /* end function checkdir() */
 
 
 
 
 
#ifdef NO_MKDIR
 
/********************/
/* Function mkdir() */
/********************/
 
int mkdir(path, mode)
ZCONST char *path;
int mode; /* ignored */
/*
* returns: 0 - successful
* -1 - failed (errno not set, however)
*/
{
char command[FILNAMSIZ+40]; /* buffer for system() call */
 
/* GRR 930416: added single quotes around path to avoid bug with
* creating directories with ampersands in name; not yet tested */
sprintf(command, "IFS=\" \t\n\" /bin/mkdir '%s' 2>/dev/null", path);
if (system(command))
return -1;
return 0;
}
 
#endif /* NO_MKDIR */
 
 
 
 
#if (!defined(MTS) || defined(SET_DIR_ATTRIB))
static int get_extattribs OF((__GPRO__ iztimes *pzt, ulg z_uidgid[2]));
 
static int get_extattribs(__G__ pzt, z_uidgid)
__GDEF
iztimes *pzt;
ulg z_uidgid[2];
{
/*---------------------------------------------------------------------------
Convert from MSDOS-format local time and date to Unix-format 32-bit GMT
time: adjust base year from 1980 to 1970, do usual conversions from
yy/mm/dd hh:mm:ss to elapsed seconds, and account for timezone and day-
light savings time differences. If we have a Unix extra field, however,
we're laughing: both mtime and atime are ours. On the other hand, we
then have to check for restoration of UID/GID.
---------------------------------------------------------------------------*/
int have_uidgid_flg;
unsigned eb_izux_flg;
 
eb_izux_flg = (G.extra_field ? ef_scan_for_izux(G.extra_field,
G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime,
#ifdef IZ_CHECK_TZ
(G.tz_is_valid ? pzt : NULL),
#else
pzt,
#endif
z_uidgid) : 0);
if (eb_izux_flg & EB_UT_FL_MTIME) {
TTrace((stderr, "\nget_extattribs: Unix e.f. modif. time = %ld\n",
pzt->mtime));
} else {
pzt->mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
}
if (eb_izux_flg & EB_UT_FL_ATIME) {
TTrace((stderr, "get_extattribs: Unix e.f. access time = %ld\n",
pzt->atime));
} else {
pzt->atime = pzt->mtime;
TTrace((stderr, "\nget_extattribs: modification/access times = %ld\n",
pzt->mtime));
}
 
/* if -X option was specified and we have UID/GID info, restore it */
have_uidgid_flg =
#ifdef RESTORE_UIDGID
(uO.X_flag && (eb_izux_flg & EB_UX2_VALID));
#else
0;
#endif
return have_uidgid_flg;
}
#endif /* !MTS || SET_DIR_ATTRIB */
 
 
 
#ifndef MTS
 
/****************************/
/* Function close_outfile() */
/****************************/
 
void close_outfile(__G) /* GRR: change to return PK-style warning level */
__GDEF
{
union {
iztimes t3; /* mtime, atime, ctime */
ztimbuf t2; /* modtime, actime */
} zt;
ulg z_uidgid[2];
int have_uidgid_flg;
 
have_uidgid_flg = get_extattribs(__G__ &(zt.t3), z_uidgid);
 
/*---------------------------------------------------------------------------
If symbolic links are supported, allocate storage for a symlink control
structure, put the uncompressed "data" and other required info in it, and
add the structure to the "deferred symlinks" chain. Since we know it's a
symbolic link to start with, we shouldn't have to worry about overflowing
unsigned ints with unsigned longs.
---------------------------------------------------------------------------*/
 
#ifdef SYMLINKS
if (G.symlnk) {
extent ucsize = (extent)G.lrec.ucsize;
# ifdef SET_SYMLINK_ATTRIBS
extent attribsize = sizeof(unsigned) +
(have_uidgid_flg ? sizeof(z_uidgid) : 0);
# else
extent attribsize = 0;
# endif
/* size of the symlink entry is the sum of
* (struct size (includes 1st '\0') + 1 additional trailing '\0'),
* system specific attribute data size (might be 0),
* and the lengths of name and link target.
*/
extent slnk_entrysize = (sizeof(slinkentry) + 1) + attribsize +
ucsize + strlen(G.filename);
slinkentry *slnk_entry;
 
if (slnk_entrysize < ucsize) {
Info(slide, 0x201, ((char *)slide,
"warning: symbolic link (%s) failed: mem alloc overflow\n",
FnFilter1(G.filename)));
fclose(G.outfile);
return;
}
 
if ((slnk_entry = (slinkentry *)malloc(slnk_entrysize)) == NULL) {
Info(slide, 0x201, ((char *)slide,
"warning: symbolic link (%s) failed: no mem\n",
FnFilter1(G.filename)));
fclose(G.outfile);
return;
}
slnk_entry->next = NULL;
slnk_entry->targetlen = ucsize;
slnk_entry->attriblen = attribsize;
# ifdef SET_SYMLINK_ATTRIBS
memcpy(slnk_entry->buf, &(G.pInfo->file_attr),
sizeof(unsigned));
if (have_uidgid_flg)
memcpy(slnk_entry->buf + 4, z_uidgid, sizeof(z_uidgid));
# endif
slnk_entry->target = slnk_entry->buf + slnk_entry->attriblen;
slnk_entry->fname = slnk_entry->target + ucsize + 1;
strcpy(slnk_entry->fname, G.filename);
 
/* move back to the start of the file to re-read the "link data" */
rewind(G.outfile);
 
if (fread(slnk_entry->target, 1, ucsize, G.outfile) != ucsize)
{
Info(slide, 0x201, ((char *)slide,
"warning: symbolic link (%s) failed\n",
FnFilter1(G.filename)));
free(slnk_entry);
fclose(G.outfile);
return;
}
fclose(G.outfile); /* close "link" file for good... */
slnk_entry->target[ucsize] = '\0';
if (QCOND2)
Info(slide, 0, ((char *)slide, "-> %s ",
FnFilter1(slnk_entry->target)));
/* add this symlink record to the list of deferred symlinks */
if (G.slink_last != NULL)
G.slink_last->next = slnk_entry;
else
G.slink_head = slnk_entry;
G.slink_last = slnk_entry;
return;
}
#endif /* SYMLINKS */
 
#ifdef QLZIP
if (G.extra_field) {
static void qlfix OF((__GPRO__ uch *ef_ptr, unsigned ef_len));
 
qlfix(__G__ G.extra_field, G.lrec.extra_field_length);
}
#endif
 
#if (defined(NO_FCHOWN))
fclose(G.outfile);
#endif
 
/* if -X option was specified and we have UID/GID info, restore it */
if (have_uidgid_flg
/* check that both uid and gid values fit into their data sizes */
&& ((ulg)(uid_t)(z_uidgid[0]) == z_uidgid[0])
&& ((ulg)(gid_t)(z_uidgid[1]) == z_uidgid[1])) {
TTrace((stderr, "close_outfile: restoring Unix UID/GID info\n"));
#if (defined(NO_FCHOWN))
if (chown(G.filename, (uid_t)z_uidgid[0], (gid_t)z_uidgid[1]))
#else
if (fchown(fileno(G.outfile), (uid_t)z_uidgid[0], (gid_t)z_uidgid[1]))
#endif
{
if (uO.qflag)
Info(slide, 0x201, ((char *)slide, CannotSetItemUidGid,
z_uidgid[0], z_uidgid[1], FnFilter1(G.filename),
strerror(errno)));
else
Info(slide, 0x201, ((char *)slide, CannotSetUidGid,
z_uidgid[0], z_uidgid[1], strerror(errno)));
}
}
 
#if (!defined(NO_FCHOWN) && defined(NO_FCHMOD))
fclose(G.outfile);
#endif
 
#if (!defined(NO_FCHOWN) && !defined(NO_FCHMOD))
/*---------------------------------------------------------------------------
Change the file permissions from default ones to those stored in the
zipfile.
---------------------------------------------------------------------------*/
 
if (fchmod(fileno(G.outfile), filtattr(__G__ G.pInfo->file_attr)))
perror("fchmod (file attributes) error");
 
fclose(G.outfile);
#endif /* !NO_FCHOWN && !NO_FCHMOD */
 
/* skip restoring time stamps on user's request */
if (uO.D_flag <= 1) {
/* set the file's access and modification times */
if (utime(G.filename, &(zt.t2))) {
if (uO.qflag)
Info(slide, 0x201, ((char *)slide, CannotSetItemTimestamps,
FnFilter1(G.filename), strerror(errno)));
else
Info(slide, 0x201, ((char *)slide, CannotSetTimestamps,
strerror(errno)));
}
}
 
#if (defined(NO_FCHOWN) || defined(NO_FCHMOD))
/*---------------------------------------------------------------------------
Change the file permissions from default ones to those stored in the
zipfile.
---------------------------------------------------------------------------*/
 
#ifndef NO_CHMOD
if (chmod(G.filename, filtattr(__G__ G.pInfo->file_attr)))
perror("chmod (file attributes) error");
#endif
#endif /* NO_FCHOWN || NO_FCHMOD */
 
} /* end function close_outfile() */
 
#endif /* !MTS */
 
 
#if (defined(SYMLINKS) && defined(SET_SYMLINK_ATTRIBS))
int set_symlnk_attribs(__G__ slnk_entry)
__GDEF
slinkentry *slnk_entry;
{
if (slnk_entry->attriblen > 0) {
# if (!defined(NO_LCHOWN))
if (slnk_entry->attriblen > sizeof(unsigned)) {
ulg *z_uidgid_p = (zvoid *)(slnk_entry->buf + sizeof(unsigned));
/* check that both uid and gid values fit into their data sizes */
if (((ulg)(uid_t)(z_uidgid_p[0]) == z_uidgid_p[0]) &&
((ulg)(gid_t)(z_uidgid_p[1]) == z_uidgid_p[1])) {
TTrace((stderr,
"set_symlnk_attribs: restoring Unix UID/GID info for\n\
%s\n",
FnFilter1(slnk_entry->fname)));
if (lchown(slnk_entry->fname,
(uid_t)z_uidgid_p[0], (gid_t)z_uidgid_p[1]))
{
Info(slide, 0x201, ((char *)slide, CannotSetItemUidGid,
z_uidgid_p[0], z_uidgid_p[1], FnFilter1(slnk_entry->fname),
strerror(errno)));
}
}
}
# endif /* !NO_LCHOWN */
# if (!defined(NO_LCHMOD))
TTrace((stderr,
"set_symlnk_attribs: restoring Unix attributes for\n %s\n",
FnFilter1(slnk_entry->fname)));
if (lchmod(slnk_entry->fname,
filtattr(__G__ *(unsigned *)(zvoid *)slnk_entry->buf)))
perror("lchmod (file attributes) error");
# endif /* !NO_LCHMOD */
}
/* currently, no error propagation... */
return PK_OK;
} /* end function set_symlnk_attribs() */
#endif /* SYMLINKS && SET_SYMLINK_ATTRIBS */
 
 
#ifdef SET_DIR_ATTRIB
/* messages of code for setting directory attributes */
# ifndef NO_CHMOD
static ZCONST char DirlistChmodFailed[] =
"warning: cannot set permissions for %s\n %s\n";
# endif
 
 
int defer_dir_attribs(__G__ pd)
__GDEF
direntry **pd;
{
uxdirattr *d_entry;
 
d_entry = (uxdirattr *)malloc(sizeof(uxdirattr) + strlen(G.filename));
*pd = (direntry *)d_entry;
if (d_entry == (uxdirattr *)NULL) {
return PK_MEM;
}
d_entry->fn = d_entry->fnbuf;
strcpy(d_entry->fn, G.filename);
 
d_entry->perms = G.pInfo->file_attr;
 
d_entry->have_uidgid = get_extattribs(__G__ &(d_entry->u.t3),
d_entry->uidgid);
return PK_OK;
} /* end function defer_dir_attribs() */
 
 
int set_direc_attribs(__G__ d)
__GDEF
direntry *d;
{
int errval = PK_OK;
 
if (UxAtt(d)->have_uidgid &&
/* check that both uid and gid values fit into their data sizes */
((ulg)(uid_t)(UxAtt(d)->uidgid[0]) == UxAtt(d)->uidgid[0]) &&
((ulg)(gid_t)(UxAtt(d)->uidgid[1]) == UxAtt(d)->uidgid[1]) &&
chown(UxAtt(d)->fn, (uid_t)UxAtt(d)->uidgid[0],
(gid_t)UxAtt(d)->uidgid[1]))
{
Info(slide, 0x201, ((char *)slide, CannotSetItemUidGid,
UxAtt(d)->uidgid[0], UxAtt(d)->uidgid[1], FnFilter1(d->fn),
strerror(errno)));
if (!errval)
errval = PK_WARN;
}
/* Skip restoring directory time stamps on user' request. */
if (uO.D_flag <= 0) {
/* restore directory timestamps */
if (utime(d->fn, &UxAtt(d)->u.t2)) {
Info(slide, 0x201, ((char *)slide, CannotSetItemTimestamps,
FnFilter1(d->fn), strerror(errno)));
if (!errval)
errval = PK_WARN;
}
}
#ifndef NO_CHMOD
if (chmod(d->fn, UxAtt(d)->perms)) {
Info(slide, 0x201, ((char *)slide, DirlistChmodFailed,
FnFilter1(d->fn), strerror(errno)));
if (!errval)
errval = PK_WARN;
}
#endif /* !NO_CHMOD */
return errval;
} /* end function set_direc_attribs() */
 
#endif /* SET_DIR_ATTRIB */
 
 
 
 
#ifdef TIMESTAMP
 
/***************************/
/* Function stamp_file() */
/***************************/
 
int stamp_file(fname, modtime)
ZCONST char *fname;
time_t modtime;
{
ztimbuf tp;
 
tp.modtime = tp.actime = modtime;
return (utime(fname, &tp));
 
} /* end function stamp_file() */
 
#endif /* TIMESTAMP */
 
 
 
 
#ifndef SFX
 
/************************/
/* Function version() */
/************************/
 
void version(__G)
__GDEF
{
#if (defined(__GNUC__) && defined(NX_CURRENT_COMPILER_RELEASE))
char cc_namebuf[40];
char cc_versbuf[40];
#else
#if (defined(__SUNPRO_C))
char cc_versbuf[17];
#else
#if (defined(__HP_cc) || defined(__IBMC__))
char cc_versbuf[25];
#else
#if (defined(__DECC_VER))
char cc_versbuf[17];
int cc_verstyp;
#else
#if (defined(CRAY) && defined(_RELEASE))
char cc_versbuf[40];
#endif /* (CRAY && _RELEASE) */
#endif /* __DECC_VER */
#endif /* __HP_cc || __IBMC__ */
#endif /* __SUNPRO_C */
#endif /* (__GNUC__ && NX_CURRENT_COMPILER_RELEASE) */
 
#if ((defined(CRAY) || defined(cray)) && defined(_UNICOS))
char os_namebuf[40];
#else
#if defined(__NetBSD__)
char os_namebuf[40];
#endif
#endif
 
/* Pyramid, NeXT have problems with huge macro expansion, too: no Info() */
sprintf((char *)slide, LoadFarString(CompiledWith),
 
#ifdef __GNUC__
# ifdef NX_CURRENT_COMPILER_RELEASE
(sprintf(cc_namebuf, "NeXT DevKit %d.%02d ",
NX_CURRENT_COMPILER_RELEASE/100, NX_CURRENT_COMPILER_RELEASE%100),
cc_namebuf),
(strlen(__VERSION__) > 8)? "(gcc)" :
(sprintf(cc_versbuf, "(gcc %s)", __VERSION__), cc_versbuf),
# else
"gcc ", __VERSION__,
# endif
#else
#if defined(__SUNPRO_C)
"Sun C ", (sprintf(cc_versbuf, "version %x", __SUNPRO_C), cc_versbuf),
#else
#if (defined(__HP_cc))
"HP C ",
(((__HP_cc% 100) == 0) ?
(sprintf(cc_versbuf, "version A.%02d.%02d",
(__HP_cc/ 10000), ((__HP_cc% 10000)/ 100))) :
(sprintf(cc_versbuf, "version A.%02d.%02d.%02d",
(__HP_cc/ 10000), ((__HP_cc% 10000)/ 100), (__HP_cc% 100))),
cc_versbuf),
#else
#if (defined(__DECC_VER))
"DEC C ",
(sprintf(cc_versbuf, "%c%d.%d-%03d",
((cc_verstyp = (__DECC_VER / 10000) % 10) == 6 ? 'T' :
(cc_verstyp == 8 ? 'S' : 'V')),
__DECC_VER / 10000000,
(__DECC_VER % 10000000) / 100000, __DECC_VER % 1000),
cc_versbuf),
#else
#if defined(CRAY) && defined(_RELEASE)
"cc ", (sprintf(cc_versbuf, "version %d", _RELEASE), cc_versbuf),
#else
#ifdef __IBMC__
"IBM C ",
(sprintf(cc_versbuf, "version %d.%d.%d",
(__IBMC__ / 100), ((__IBMC__ / 10) % 10), (__IBMC__ % 10)),
cc_versbuf),
#else
#ifdef __VERSION__
# ifndef IZ_CC_NAME
# define IZ_CC_NAME "cc "
# endif
IZ_CC_NAME, __VERSION__
#else
# ifndef IZ_CC_NAME
# define IZ_CC_NAME "cc"
# endif
IZ_CC_NAME, "",
#endif /* ?__VERSION__ */
#endif /* ?__IBMC__ */
#endif /* ?(CRAY && _RELEASE) */
#endif /* ?__DECC_VER */
#endif /* ?__HP_cc */
#endif /* ?__SUNPRO_C */
#endif /* ?__GNUC__ */
 
#ifndef IZ_OS_NAME
# define IZ_OS_NAME "Unix"
#endif
IZ_OS_NAME,
 
#if defined(sgi) || defined(__sgi)
" (Silicon Graphics IRIX)",
#else
#ifdef sun
# ifdef sparc
# ifdef __SVR4
" (Sun SPARC/Solaris)",
# else /* may or may not be SunOS */
" (Sun SPARC)",
# endif
# else
# if defined(sun386) || defined(i386)
" (Sun 386i)",
# else
# if defined(mc68020) || defined(__mc68020__)
" (Sun 3)",
# else /* mc68010 or mc68000: Sun 2 or earlier */
" (Sun 2)",
# endif
# endif
# endif
#else
#ifdef __hpux
" (HP-UX)",
#else
#ifdef __osf__
" (DEC OSF/1)",
#else
#ifdef _AIX
" (IBM AIX)",
#else
#ifdef aiws
" (IBM RT/AIX)",
#else
#if defined(CRAY) || defined(cray)
# ifdef _UNICOS
(sprintf(os_namebuf, " (Cray UNICOS release %d)", _UNICOS), os_namebuf),
# else
" (Cray UNICOS)",
# endif
#else
#if defined(uts) || defined(UTS)
" (Amdahl UTS)",
#else
#ifdef NeXT
# ifdef mc68000
" (NeXTStep/black)",
# else
" (NeXTStep for Intel)",
# endif
#else /* the next dozen or so are somewhat order-dependent */
#ifdef LINUX
# ifdef __ELF__
" (Linux ELF)",
# else
" (Linux a.out)",
# endif
#else
#ifdef MINIX
" (Minix)",
#else
#ifdef M_UNIX
" (SCO Unix)",
#else
#ifdef M_XENIX
" (SCO Xenix)",
#else
#ifdef __NetBSD__
# ifdef NetBSD0_8
(sprintf(os_namebuf, " (NetBSD 0.8%c)", (char)(NetBSD0_8 - 1 + 'A')),
os_namebuf),
# else
# ifdef NetBSD0_9
(sprintf(os_namebuf, " (NetBSD 0.9%c)", (char)(NetBSD0_9 - 1 + 'A')),
os_namebuf),
# else
# ifdef NetBSD1_0
(sprintf(os_namebuf, " (NetBSD 1.0%c)", (char)(NetBSD1_0 - 1 + 'A')),
os_namebuf),
# else
(BSD4_4 == 0.5)? " (NetBSD before 0.9)" : " (NetBSD 1.1 or later)",
# endif
# endif
# endif
#else
#ifdef __FreeBSD__
(BSD4_4 == 0.5)? " (FreeBSD 1.x)" : " (FreeBSD 2.0 or later)",
#else
#ifdef __bsdi__
(BSD4_4 == 0.5)? " (BSD/386 1.0)" : " (BSD/386 1.1 or later)",
#else
#ifdef __386BSD__
(BSD4_4 == 1)? " (386BSD, post-4.4 release)" : " (386BSD)",
#else
#ifdef __CYGWIN__
" (Cygwin)",
#else
#if defined(i686) || defined(__i686) || defined(__i686__)
" (Intel 686)",
#else
#if defined(i586) || defined(__i586) || defined(__i586__)
" (Intel 586)",
#else
#if defined(i486) || defined(__i486) || defined(__i486__)
" (Intel 486)",
#else
#if defined(i386) || defined(__i386) || defined(__i386__)
" (Intel 386)",
#else
#ifdef pyr
" (Pyramid)",
#else
#ifdef ultrix
# ifdef mips
" (DEC/MIPS)",
# else
# ifdef vax
" (DEC/VAX)",
# else /* __alpha? */
" (DEC/Alpha)",
# endif
# endif
#else
#ifdef gould
" (Gould)",
#else
#ifdef MTS
" (MTS)",
#else
#ifdef __convexc__
" (Convex)",
#else
#ifdef __QNX__
" (QNX 4)",
#else
#ifdef __QNXNTO__
" (QNX Neutrino)",
#else
#ifdef Lynx
" (LynxOS)",
#else
#ifdef __APPLE__
# ifdef __i386__
" Mac OS X Intel i32",
# else
# ifdef __ppc__
" Mac OS X PowerPC",
# else
# ifdef __ppc64__
" Mac OS X PowerPC64",
# else
" Mac OS X",
# endif /* __ppc64__ */
# endif /* __ppc__ */
# endif /* __i386__ */
#else
"",
#endif /* Apple */
#endif /* Lynx */
#endif /* QNX Neutrino */
#endif /* QNX 4 */
#endif /* Convex */
#endif /* MTS */
#endif /* Gould */
#endif /* DEC */
#endif /* Pyramid */
#endif /* 386 */
#endif /* 486 */
#endif /* 586 */
#endif /* 686 */
#endif /* Cygwin */
#endif /* 386BSD */
#endif /* BSDI BSD/386 */
#endif /* NetBSD */
#endif /* FreeBSD */
#endif /* SCO Xenix */
#endif /* SCO Unix */
#endif /* Minix */
#endif /* Linux */
#endif /* NeXT */
#endif /* Amdahl */
#endif /* Cray */
#endif /* RT/AIX */
#endif /* AIX */
#endif /* OSF/1 */
#endif /* HP-UX */
#endif /* Sun */
#endif /* SGI */
 
#ifdef __DATE__
" on ", __DATE__
#else
"", ""
#endif
);
 
(*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
 
} /* end function version() */
 
#endif /* !SFX */
 
 
 
 
#ifdef QLZIP
 
struct qdirect {
long d_length __attribute__ ((packed)); /* file length */
unsigned char d_access __attribute__ ((packed)); /* file access type */
unsigned char d_type __attribute__ ((packed)); /* file type */
long d_datalen __attribute__ ((packed)); /* data length */
long d_reserved __attribute__ ((packed));/* Unused */
short d_szname __attribute__ ((packed)); /* size of name */
char d_name[36] __attribute__ ((packed));/* name area */
long d_update __attribute__ ((packed)); /* last update */
long d_refdate __attribute__ ((packed));
long d_backup __attribute__ ((packed)); /* EOD */
};
 
#define LONGID "QDOS02"
#define EXTRALEN (sizeof(struct qdirect) + 8)
#define JBLONGID "QZHD"
#define JBEXTRALEN (sizeof(jbextra) - 4 * sizeof(char))
 
typedef struct {
char eb_header[4] __attribute__ ((packed)); /* place_holder */
char longid[8] __attribute__ ((packed));
struct qdirect header __attribute__ ((packed));
} qdosextra;
 
typedef struct {
char eb_header[4]; /* place_holder */
char longid[4];
struct qdirect header;
} jbextra;
 
 
 
/* The following two functions SH() and LG() convert big-endian short
* and long numbers into native byte order. They are some kind of
* counterpart to the generic UnZip's makeword() and makelong() functions.
*/
static ush SH(ush val)
{
uch swapbuf[2];
 
swapbuf[1] = (uch)(val & 0xff);
swapbuf[0] = (uch)(val >> 8);
return (*(ush *)swapbuf);
}
 
 
 
static ulg LG(ulg val)
{
/* convert the big-endian unsigned long number `val' to the machine
* dependent representation
*/
ush swapbuf[2];
 
swapbuf[1] = SH((ush)(val & 0xffff));
swapbuf[0] = SH((ush)(val >> 16));
return (*(ulg *)swapbuf);
}
 
 
 
static void qlfix(__G__ ef_ptr, ef_len)
__GDEF
uch *ef_ptr;
unsigned ef_len;
{
while (ef_len >= EB_HEADSIZE)
{
unsigned eb_id = makeword(EB_ID + ef_ptr);
unsigned eb_len = makeword(EB_LEN + ef_ptr);
 
if (eb_len > (ef_len - EB_HEADSIZE)) {
/* discovered some extra field inconsistency! */
Trace((stderr,
"qlfix: block length %u > rest ef_size %u\n", eb_len,
ef_len - EB_HEADSIZE));
break;
}
 
switch (eb_id) {
case EF_QDOS:
{
struct _ntc_
{
long id;
long dlen;
} ntc;
long dlen = 0;
 
qdosextra *extra = (qdosextra *)ef_ptr;
jbextra *jbp = (jbextra *)ef_ptr;
 
if (!strncmp(extra->longid, LONGID, strlen(LONGID)))
{
if (eb_len != EXTRALEN)
if (uO.qflag)
Info(slide, 0x201, ((char *)slide,
"warning: invalid length in Qdos field for %s\n",
FnFilter1(G.filename)));
else
Info(slide, 0x201, ((char *)slide,
"warning: invalid length in Qdos field"));
 
if (extra->header.d_type)
{
dlen = extra->header.d_datalen;
}
}
 
if (!strncmp(jbp->longid, JBLONGID, strlen(JBLONGID)))
{
if (eb_len != JBEXTRALEN)
if (uO.qflag)
Info(slide, 0x201, ((char *)slide,
"warning: invalid length in QZ field for %s\n",
FnFilter1(G.filename)));
else
Info(slide, 0x201, ((char *)slide,
"warning: invalid length in QZ field"));
if (jbp->header.d_type)
{
dlen = jbp->header.d_datalen;
}
}
 
if ((long)LG(dlen) > 0)
{
zfseeko(G.outfile, -8, SEEK_END);
fread(&ntc, 8, 1, G.outfile);
if (ntc.id != *(long *)"XTcc")
{
ntc.id = *(long *)"XTcc";
ntc.dlen = dlen;
fwrite (&ntc, 8, 1, G.outfile);
}
Info(slide, 0x201, ((char *)slide, "QData = %d", LG(dlen)));
}
return; /* finished, cancel further extra field scanning */
}
 
default:
Trace((stderr,"qlfix: unknown extra field block, ID=%d\n",
eb_id));
}
 
/* Skip this extra field block */
ef_ptr += (eb_len + EB_HEADSIZE);
ef_len -= (eb_len + EB_HEADSIZE);
}
}
#endif /* QLZIP */
/programs/fs/unzip60/unix/unxcfg.h
0,0 → 1,230
/*
Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
 
See the accompanying file LICENSE, version 2009-Jan-02 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*---------------------------------------------------------------------------
Unix specific configuration section:
---------------------------------------------------------------------------*/
 
#ifndef __unxcfg_h
#define __unxcfg_h
 
 
/* LARGE FILE SUPPORT - 10/6/04 EG */
/* This needs to be set before the includes so they set the right sizes */
 
#if (defined(NO_LARGE_FILE_SUPPORT) && defined(LARGE_FILE_SUPPORT))
# undef LARGE_FILE_SUPPORT
#endif
 
/* Automatically set ZIP64_SUPPORT if LFS */
#ifdef LARGE_FILE_SUPPORT
# if (!defined(NO_ZIP64_SUPPORT) && !defined(ZIP64_SUPPORT))
# define ZIP64_SUPPORT
# endif
#endif
 
/* NO_ZIP64_SUPPORT takes preceedence over ZIP64_SUPPORT */
#if defined(NO_ZIP64_SUPPORT) && defined(ZIP64_SUPPORT)
# undef ZIP64_SUPPORT
#endif
 
#ifdef LARGE_FILE_SUPPORT
/* 64-bit Large File Support */
 
/* The following Large File Summit (LFS) defines turn on large file support
on Linux (probably 2.4 or later kernel) and many other unixen */
 
/* These have to be before any include that sets types so the large file
versions of the types are set in the includes */
 
# define _LARGEFILE_SOURCE /* some OSes need this for fseeko */
# define _LARGEFILE64_SOURCE
# define _FILE_OFFSET_BITS 64 /* select default interface as 64 bit */
# define _LARGE_FILES /* some OSes need this for 64-bit off_t */
# define __USE_LARGEFILE64
#endif /* LARGE_FILE_SUPPORT */
 
 
#include <sys/types.h> /* off_t, time_t, dev_t, ... */
#include <sys/stat.h>
 
#ifdef NO_OFF_T
typedef long zoff_t;
#else
typedef off_t zoff_t;
#endif
#define ZOFF_T_DEFINED
typedef struct stat z_stat;
#define Z_STAT_DEFINED
 
#ifndef COHERENT
# include <fcntl.h> /* O_BINARY for open() w/o CR/LF translation */
#else /* COHERENT */
# ifdef _I386
# include <fcntl.h> /* Coherent 4.0.x, Mark Williams C */
# else
# include <sys/fcntl.h> /* Coherent 3.10, Mark Williams C */
# endif
# define SHORT_SYMS
# ifndef __COHERENT__ /* Coherent 4.2 has tzset() */
# define tzset settz
# endif
#endif /* ?COHERENT */
 
#ifndef NO_PARAM_H
# ifdef NGROUPS_MAX
# undef NGROUPS_MAX /* SCO bug: defined again in <sys/param.h> */
# endif
# ifdef BSD
# define TEMP_BSD /* may be defined again in <sys/param.h> */
# undef BSD
# endif
# include <sys/param.h> /* conflict with <sys/types.h>, some systems? */
# ifdef TEMP_BSD
# undef TEMP_BSD
# ifndef BSD
# define BSD
# endif
# endif
#endif /* !NO_PARAM_H */
 
#ifdef __osf__
# define DIRENT
# ifdef BSD
# undef BSD
# endif
#endif /* __osf__ */
 
#ifdef __CYGWIN__
# include <unistd.h>
# define DIRENT
# define HAVE_TERMIOS_H
# ifndef timezone
# define timezone _timezone
# endif
#endif
 
#ifdef BSD
# include <sys/time.h>
# include <sys/timeb.h>
# if (defined(_AIX) || defined(__GLIBC__) || defined(__GNU__))
# include <time.h>
# endif
#else
# include <time.h>
struct tm *gmtime(), *localtime();
#endif
 
#if (defined(BSD4_4) || (defined(SYSV) && defined(MODERN)))
# include <unistd.h> /* this includes utime.h on SGIs */
# if (defined(BSD4_4) || defined(linux) || defined(__GLIBC__))
# include <utime.h>
# define GOT_UTIMBUF
# endif
# if (!defined(GOT_UTIMBUF) && (defined(__hpux) || defined(__SUNPRO_C)))
# include <utime.h>
# define GOT_UTIMBUF
# endif
# if (!defined(GOT_UTIMBUF) && defined(__GNU__))
# include <utime.h>
# define GOT_UTIMBUF
# endif
#endif
#if (defined(__DGUX__) && !defined(GOT_UTIMBUF))
/* DG/UX requires this because of a non-standard struct utimebuf */
# include <utime.h>
# define GOT_UTIMBUF
#endif
 
#if (defined(V7) || defined(pyr_bsd))
# define strchr index
# define strrchr rindex
#endif
#ifdef V7
# define O_RDONLY 0
# define O_WRONLY 1
# define O_RDWR 2
#endif
 
#if defined(NO_UNICODE_SUPPORT) && defined(UNICODE_SUPPORT)
/* disable Unicode (UTF-8) support when requested */
# undef UNICODE_SUPPORT
#endif
 
#if (defined(_MBCS) && defined(NO_MBCS))
/* disable MBCS support when requested */
# undef _MBCS
#endif
 
#if (!defined(NO_SETLOCALE) && !defined(_MBCS))
# if (!defined(UNICODE_SUPPORT) || !defined(UTF8_MAYBE_NATIVE))
/* enable setlocale here, unless this happens later for UTF-8 and/or
* MBCS support */
# include <locale.h>
# ifndef SETLOCALE
# define SETLOCALE(category, locale) setlocale(category, locale)
# endif
# endif
#endif
#ifndef NO_SETLOCALE
# if (!defined(NO_WORKING_ISPRINT) && !defined(HAVE_WORKING_ISPRINT))
/* enable "enhanced" unprintable chars detection in fnfilter() */
# define HAVE_WORKING_ISPRINT
# endif
#endif
 
#ifdef MINIX
# include <stdio.h>
#endif
#if (!defined(HAVE_STRNICMP) & !defined(NO_STRNICMP))
# define NO_STRNICMP
#endif
#ifndef DATE_FORMAT
# define DATE_FORMAT DF_MDY /* GRR: customize with locale.h somehow? */
#endif
#define lenEOL 1
#ifdef EBCDIC
# define PutNativeEOL *q++ = '\n';
#else
# define PutNativeEOL *q++ = native(LF);
#endif
#define SCREENSIZE(ttrows, ttcols) screensize(ttrows, ttcols)
#define SCREENWIDTH 80
#define SCREENLWRAP 1
#define USE_EF_UT_TIME
#if (!defined(NO_LCHOWN) || !defined(NO_LCHMOD))
# define SET_SYMLINK_ATTRIBS
#endif
#ifdef MTS
# ifdef SET_DIR_ATTRIB
# undef SET_DIR_ATTRIB
# endif
#else /* !MTS */
# define SET_DIR_ATTRIB
# if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP)) /* GRR 970513 */
# define TIMESTAMP
# endif
# define RESTORE_UIDGID
#endif /* ?MTS */
 
/* Static variables that we have to add to Uz_Globs: */
#define SYSTEM_SPECIFIC_GLOBALS \
int created_dir, renamed_fullpath;\
char *rootpath, *buildpath, *end;\
ZCONST char *wildname;\
char *dirname, matchname[FILNAMSIZ];\
int rootlen, have_dirname, dirnamelen, notfirstcall;\
zvoid *wild_dir;
 
/* created_dir, and renamed_fullpath are used by both mapname() and */
/* checkdir(). */
/* rootlen, rootpath, buildpath and end are used by checkdir(). */
/* wild_dir, dirname, wildname, matchname[], dirnamelen, have_dirname, */
/* and notfirstcall are used by do_wild(). */
 
#endif /* !__unxcfg_h */
/programs/fs/unzip60/unix/zipgrep
0,0 → 1,105
#!/bin/sh
#
# zipgrep: Use unzip and egrep to search the specified members of a
# Zip archive for a string or pattern. Search all members if no members
# are specified explicitly. The script attempts to handle egrep's "-h"
# and "-l" options internally.
#
# This script assumes that the desired "unzip" and "egrep" (and "sed")
# programs are on the user's PATH.
#
 
pat=""
opt=""
while test $# -ne 0; do
case "$1" in
-e | -f) opt="$opt $1"; shift; pat="$1";;
-*) opt="$opt $1";;
*) if test -z "$pat"; then
pat="$1"
else
break;
fi;;
esac
shift
done
 
if test $# = 0; then
echo usage: `basename "$0"` "[egrep_options] pattern zipfile [members...]"
echo Uses unzip and egrep to search the zip members for a string or pattern.
exit 1
fi
zipfile="$1"; shift
 
list=0
silent=0
opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
case "$opt" in
*l*) list=1; opt=`echo $opt | sed s/l//`
esac
case "$opt" in
*h*) silent=1
esac
if test -n "$opt"; then
opt="-$opt"
fi
 
status_grep_global=1
IFS='
'
 
# Escape shell-special characters in "pat".
pat=` echo "$pat" | \
sed -e 's/\\\\/\\\\\\\\/g' -e 's/|/\\\|/g' -e 's/&/\\\&/g' `
 
# Use "unzip -Z1" to get a listing of the specified members from the
# specified archive. Escape any backslashes in a file name.
for i in `unzip -Z1 "$zipfile" ${1+"$@"} | sed -e 's/\\\\/\\\\\\\\/g' `; do
if test $list -eq 1; then
# "-l": Show only the archive member name, not the matching line(s).
unzip -p-L "$zipfile" "$i" | \
egrep $opt "$pat" > /dev/null && echo "$i"
status_grep=$?
elif test $silent -eq 1; then
# "-h": Show only the matching line(s), not the archive member name.
# ("-s" in "opt" will silence "egrep", stopping all output.)
unzip -p-L "$zipfile" "$i" | \
egrep $opt "$pat"
status_grep=$?
else
# Escape (or re-escape) shell-special characters in the archive
# member name, "i".
i=` echo "$i" | \
sed -e 's/\\\\/\\\\\\\\/g' -e 's/|/\\\|/g' -e 's/&/\\\&/g' `
 
# Globally, send fd 4 to stdout. In the pipeline, send normal
# stdout to fd 4, and send grep status to fd 3. Collect fd 3
# with ``.
exec 4>&1
status_grep=` ( \
( unzip -p-L "$zipfile" "$i" | \
egrep $opt "$pat" 1>&4 ; echo $? >&3 ) 4>&1 | \
sed "s|^|${i}:|" 1>&4 \
) 3>&1 `
fi
 
# Save the primary command status. (May be the grep status.)
sts=$?
# If this grep status was zero, set the global grep status to zero.
test "$status_grep" -eq 0 && status_grep_global=0
# If this grep status was not zero or one, exit now.
test "$status_grep" -gt 1 && exit "$status_grep"
 
done
 
# If "sts" is good (0), then exit with the global grep status.
# Else, when "sts" is bad, exit with the worst status we can find.
if test $sts -eq 0 ; then
exit $status_grep_global
else
if test "$status_grep" -gt 1 ; then
exit "$status_grep"
else
exit $sts
fi
fi