Commit 42e72ef5 authored by Reinhard Tartler's avatar Reinhard Tartler

Imported nxcompext-3.1.0-2.tar.gz

Summary: Imported nxcompext-3.1.0-2.tar.gz Keywords: Imported nxcompext-3.1.0-2.tar.gz into Git repository
parent a840692e
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <zlib.h>
#include "NXlib.h"
#include "Alpha.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define ALPHA_COMPRESSION_LEVEL 1
#define ALPHA_COMPRESSION_THRESHOLD 32
#define ALPHA_COMPRESSION_STRATEGY Z_RLE
static int alphaCompressionLevel = ALPHA_COMPRESSION_LEVEL;
static int alphaCompressionThreshold = ALPHA_COMPRESSION_THRESHOLD;
static int alphaCompressionStrategy = ALPHA_COMPRESSION_STRATEGY;
char *AlphaCompressData(const char *data, unsigned int size, unsigned int *compressed_size)
{
return ZCompressData(data, size, alphaCompressionThreshold, alphaCompressionLevel,
alphaCompressionStrategy, compressed_size);
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Alpha_H
#define Alpha_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *AlphaCompressData(
#if NeedFunctionPrototypes
const char* /* data */,
unsigned int /* size */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Alpha_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "NXlib.h"
#include "Bitmap.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
char *BitmapCompressData(XImage *image, unsigned int *size)
{
if (image -> bits_per_pixel != 32)
{
#ifdef TEST
fprintf(stderr, "******BitmapCompressData: Nothing to do with image of [%d] bpp and size [%d].\n",
image -> bits_per_pixel, image -> bytes_per_line * image -> height);
#endif
*size = image -> bytes_per_line * image -> height;
return image -> data;
}
else
{
/*
* Remove the 4th byte from the bitmap.
*/
char *data;
char *next_src;
char *next_dst;
#ifdef TEST
if (image -> bytes_per_line != 4 * image -> width)
{
fprintf(stderr, "******BitmapCompressData: PANIC! Image as [%d] bytes per line with expected [%d].\n",
image -> bytes_per_line, 4 * image -> width);
return NULL;
}
#endif
*size = image -> width * image -> height * 3;
data = Xmalloc(*size);
if (data == NULL)
{
#ifdef PANIC
fprintf(stderr, "******BitmapCompressData: PANIC! Failed to allocate [%d] bytes for the destination.\n",
*size);
#endif
*size = image -> bytes_per_line * image -> height;
return image -> data;
}
next_src = image -> data;
next_dst = data;
if (image -> byte_order == LSBFirst)
{
while (next_src < image -> data +
image -> bytes_per_line * image -> height)
{
*next_dst++ = *next_src++;
*next_dst++ = *next_src++;
*next_dst++ = *next_src++;
next_src++;
}
}
else
{
while (next_src < image -> data +
image -> bytes_per_line * image -> height)
{
next_src++;
*next_dst++ = *next_src++;
*next_dst++ = *next_src++;
*next_dst++ = *next_src++;
}
}
return data;
}
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Bitmap_H
#define Bitmap_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *BitmapCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Bitmap_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <signal.h>
#include "os.h"
#include "NXlib.h"
#include "Clean.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
int CleanXYImage(XImage *image)
{
int i, j, k, plane;
int bitsToClean = (image -> bytes_per_line << 3) - image -> width - image -> xoffset;
unsigned int bytesToClean = bitsToClean >> 3;
bitsToClean &= 7;
for (k = 0; k < image -> depth; k++)
{
plane = k * (image -> bytes_per_line * image -> height);
for (i = 1; i <= image -> height; i++)
{
if (image -> byte_order == image -> bitmap_bit_order)
{
for (j = 1; j <= bytesToClean; j++)
{
image -> data[plane + i * (image -> bytes_per_line) - j] = 0x00;
}
}
else
{
for (j = bytesToClean; j >= 1; j--)
{
image -> data[plane + i * (image -> bytes_per_line) - j] = 0x00;
}
}
if (image -> bitmap_bit_order == MSBFirst)
{
image -> data[plane + i * (image -> bytes_per_line) - j] &= 0xff << bitsToClean;
}
else
{
image -> data[plane + i * (image -> bytes_per_line) - j] &= 0xff >> bitsToClean;
}
}
}
return 1;
}
int CleanZImage(XImage *image)
{
unsigned int bytesToClean;
unsigned int j;
unsigned int imageLength;
#ifdef TEST
fprintf(stderr, "*****CleanZImage: Going to clean image of [%d] bits per pixel.\n",
image -> bits_per_pixel);
#endif
switch (image -> bits_per_pixel)
{
case 32:
{
/*
* The caller should pay attention at extracting
* the alpha channel prior to cleaning the image.
* Cleaning an image which is carrying the alpha
* channel will result in the image being treated
* as fully transparent.
*/
register int i;
bytesToClean = image -> bytes_per_line * image -> height;
#ifdef DEBUG
fprintf(stderr, "*****CleanZImage: Cleaning [%d] bytes with bits per pixel [%d] "
"width [%d] bytes per line [%d] height [%d].\n", bytesToClean,
image -> bits_per_pixel, image -> width, image ->
bytes_per_line, image -> height);
#endif
if (image -> byte_order == LSBFirst)
{
for (i = 3; i < bytesToClean; i += 4)
{
((unsigned char *) image -> data)[i] = 0x00;
}
}
else
{
for (i = 0; i < bytesToClean; i += 4)
{
((unsigned char *) image -> data)[i] = 0x00;
}
}
break;
}
case 24:
case 15:
case 16:
case 8:
{
register int i, j;
bytesToClean = image -> bytes_per_line -
((image -> width * image -> bits_per_pixel) >> 3);
for (i = 1; i <= image -> height; i++)
{
for (j = bytesToClean; j > 0; j--)
{
((unsigned char *) image -> data)[(i * image -> bytes_per_line) - j] = 0x00;
}
}
break;
}
default:
{
#ifdef PANIC
fprintf(stderr, "*****CleanZImage: PANIC! Cannot clean image with [%d] bits per pixel.\n",
image -> bits_per_pixel);
#endif
}
}
/*
* Clean the padding bytes at the real
* end of the buffer.
*/
imageLength = image -> bytes_per_line * image -> height;
bytesToClean = imageLength % 4;
for (j = 0; j < bytesToClean; j++)
{
((unsigned char *)image -> data)[(imageLength + j)] = 0x00;
}
return 1;
}
/*
* Copy a clean version of src_image into dst_image.
* This code is not taking care of the image format.
* The agent doesn't use it and you have to consider
* it unsupported.
*/
int CopyAndCleanImage(XImage *src_image, XImage *dst_image)
{
register long data_size;
register int i;
data_size = (src_image -> bytes_per_line * src_image -> height) >> 2;
#ifdef WARNING
fprintf(stderr, "******CleanImage: WARNING! Function called with image of [%d] bits per pixel.\n",
src_image -> bits_per_pixel);
#endif
switch (src_image -> bits_per_pixel)
{
case 32:
{
unsigned int mask;
if (src_image -> byte_order == MSBFirst)
{
mask = 0xffffff00;
}
else
{
mask = 0x00ffffff;
}
for (i = 0; i < data_size; i++)
{
((unsigned int *)dst_image -> data)[i] = ((unsigned int *)src_image -> data)[i] & mask;
}
break;
}
case 24:
{
unsigned int bytes_to_clean;
for (i = 0; i < data_size; i++)
{
((unsigned int *)dst_image -> data)[i] = ((unsigned int *)src_image -> data)[i];
}
bytes_to_clean = dst_image -> bytes_per_line - ((dst_image -> width *
dst_image -> bits_per_pixel) >> 3);
if (bytes_to_clean)
{
register unsigned int mask = 0xffffffff;
register int line_size;
register int i;
line_size = dst_image -> bytes_per_line >> 2;
if (dst_image -> byte_order == MSBFirst)
{
mask = mask << (bytes_to_clean << 3);
}
else
{
mask = mask >> (bytes_to_clean << 3);
}
for (i = 0; i < dst_image -> height;)
{
((unsigned char *)dst_image -> data)[(++i * line_size) -1] &= mask;
}
}
break;
}
case 15:
case 16:
{
for (i = 0; i < data_size; i++)
{
((unsigned int *) dst_image -> data)[i] = ((unsigned int *) src_image -> data)[i];
}
if (src_image -> width & 0x00000001)
{
int card32_per_line = dst_image -> bytes_per_line >> 2;
for (i = 0; i < dst_image -> height;)
{
((unsigned int *) dst_image -> data)[(++i * card32_per_line) -1] &= 0x0000ffff;
}
}
break;
}
case 8:
{
unsigned int mask = 0x00000000;
switch (dst_image -> width % 4)
{
case 3:
{
mask = 0x00ffffff;
break;
}
case 2:
{
mask = 0x0000ffff;
break;
}
case 1:
{
mask = 0x000000ff;
break;
}
default:
{
/*
* Nothing to clean.
*/
break;
}
}
for (i = 0; i < data_size; i++)
{
((unsigned int *) dst_image -> data)[i] = ((unsigned int *) src_image -> data)[i];
}
if (mask)
{
int card32_per_line;
int i;
card32_per_line = dst_image -> bytes_per_line >> 2;
for (i = 0; i < dst_image -> height; i++)
{
((unsigned int *) dst_image -> data)[(++i * card32_per_line) -1] &= mask;
}
}
break;
}
default:
{
#ifdef PANIC
fprintf(stderr, "******CleanImage: PANIC! Cannot clean image of [%d] bits per pixel.\n",
src_image -> bits_per_pixel);
#endif
return 0;
}
}
return 1;
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Clean_H
#define Clean_H
#ifdef __cplusplus
extern "C" {
#endif
#include "Xlib.h"
int CleanXYImage(XImage *image);
int CleanZImage(XImage *image);
int CopyAndCleanImage(XImage *src_image, XImage *dst_image);
#ifdef __cplusplus
}
#endif
#endif /* Clean_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <zlib.h>
#include "NXlib.h"
#include "Colormap.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define COLORMAP_COMPRESSION_LEVEL 4
#define COLORMAP_COMPRESSION_THRESHOLD 32
#define COLORMAP_COMPRESSION_STRATEGY Z_DEFAULT_STRATEGY
static int colormapCompressionLevel = COLORMAP_COMPRESSION_LEVEL;
static int colormapCompressionThreshold = COLORMAP_COMPRESSION_THRESHOLD;
static int colormapCompressionStrategy = COLORMAP_COMPRESSION_STRATEGY;
char *ColormapCompressData(const char *data, unsigned int size, unsigned int *compressed_size)
{
return ZCompressData(data, size, colormapCompressionThreshold, colormapCompressionLevel,
colormapCompressionStrategy, compressed_size);
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Colormap_H
#define Colormap_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *ColormapCompressData(
#if NeedFunctionPrototypes
const char* /* data */,
unsigned int /* size */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Colormap_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Jpeg_H
#define Jpeg_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *JpegCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
int /* level */,
int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Jpeg_H */
Copyright (C) 2001, 2007 NoMachine - http://www.nomachine.com/.
NXCOMPEXT library and NX extensions to X are copyright of NoMachine.
Redistribution and use of this software is allowed according to the
following terms:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License Version 2, and
not any other version, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTA-
BILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, you can request a copy to NoMachine
or write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA
All rights reserved.
############################################################################
# #
# Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com. #
# #
# NXCOMPEXT, NX protocol compression and NX extensions to this software #
# are copyright of NoMachine. Redistribution and use of the present #
# software is allowed according to terms specified in the file LICENSE #
# which comes in the source distribution. #
# #
# Check http://www.nomachine.com/licensing.html for applicability. #
# #
# NX and NoMachine are trademarks of NoMachine S.r.l. #
# #
# All rights reserved. #
# #
############################################################################
#
# Get values from configure script.
#
VERSION=@VERSION@
LIBVERSION=@LIBVERSION@
#
# We want to enable really all warnings. -Wredundant-decls,
# though, gives a warning caused by pthread.h and unistd.h.
#
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@ @X_CFLAGS@ @DEFS@ \
-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations -Wnested-externs
CXXINCLUDES = -I. -I../nxcomp
CXXDEFINES =
CC = @CC@
CCFLAGS = @CFLAGS@ @X_CFLAGS@ @DEFS@ \
-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations -Wnested-externs
CCINCLUDES = -I. -I../nxcomp
CCDEFINES =
LDFLAGS = @LDFLAGS@ -L../nxcomp
LIBS = @LIBS@ -lz -lX11 -lXcomp
#
# Only if THREADS is defined
#
# LIBS = @LIBS@ -lz -ljpeg -lpthread -lX11 -lXcomp
#
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
man1dir = @mandir@/man1
VPATH = @srcdir@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
#
# This should be autodetected.
#
MAKEDEPEND = @MAKEDEPEND@
DEPENDINCLUDES = -I/usr/include/c++ -I/usr/include/g++ -I/usr/include/g++-3
.SUFFIXES: .cpp.c
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(CXXINCLUDES) $<
.c.o:
$(CC) -c $(CCFLAGS) $(CCINCLUDES) $<
LIBRARY = Xcompext
LIBNAME = lib$(LIBRARY)
LIBFULL = lib$(LIBRARY).so.$(VERSION)
LIBLOAD = lib$(LIBRARY).so.$(LIBVERSION)
LIBSHARED = lib$(LIBRARY).so
LIBARCHIVE = lib$(LIBRARY).a
LIBCYGSHARED = cyg$(LIBRARY).dll
LIBCYGARCHIVE = lib$(LIBRARY).dll.a
all: depend @ALL@
MSRC=
CSRC= NXlib.c \
Clean.c \
Mask.c \
Colormap.c \
Alpha.c \
Jpeg.c \
Pgn.c \
Bitmap.c \
Rgb.c \
Rle.c \
Z.c
CXXSRC=
MOBJ = $(MSRC:.c=.o)
COBJ = $(CSRC:.c=.o)
CXXOBJ = $(CXXSRC:.cpp=.o)
$(LIBFULL): $(CXXOBJ) $(COBJ)
$(CXX) -o $@ $(LDFLAGS) $(CXXOBJ) $(COBJ) $(LIBS)
$(LIBLOAD): $(LIBFULL)
rm -f $(LIBLOAD)
ln -s $(LIBFULL) $(LIBLOAD)
$(LIBSHARED): $(LIBFULL)
rm -f $(LIBSHARED)
ln -s $(LIBFULL) $(LIBSHARED)
$(LIBARCHIVE): $(CXXOBJ) $(COBJ)
rm -f $(LIBARCHIVE)
ar clq $(LIBARCHIVE) $(CXXOBJ) $(COBJ)
ranlib $(LIBARCHIVE)
$(LIBCYGSHARED): $(LIBARCHIVE)
$(CC) -shared -o $(LIBCYGSHARED) \
-Wl,--out-implib=$(LIBCYGARCHIVE) \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import \
-Wl,--whole-archive $(LIBARCHIVE) \
-Wl,--no-whole-archive $(LIBS) \
$(LDFLAGS)
$(LIBCYGARCHIVE): $(LIBCYGSHARED)
depends: depend.status
depend: depend.status
depend.status:
if [ -x $(MAKEDEPEND) ] ; then \
$(MAKEDEPEND) $(CXXINCLUDES) $(CCINCLUDES) \
$(DEPENDINCLUDES) -f Makefile $(MSRC) $(CSRC) \
$(CXXSRC) 2>/dev/null; \
fi
touch depend.status
install: install.bin install.man
install.bin:
install.man:
clean:
-rm -f *~ *.o *.bak *.orig *.rej st?????? core core.* *.out.* \
@ALL@
distclean: clean
-rm -rf autom4te.cache config.status config.log \
config.cache depend.status Makefile tags
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Mask_H
#define Mask_H
#ifdef __cplusplus
extern "C" {
#endif
#include "Xlib.h"
extern int MaskImage(const ColorMask *mask, XImage *src_image, XImage *dst_image);
extern int MaskInPlaceImage(const ColorMask *mask, XImage *image);
extern int PackImage(unsigned int method, unsigned int src_data_size, XImage *src_image,
unsigned int dst_data_size, XImage *dst_image);
int FindLSB(int word);
#ifdef __cplusplus
}
#endif
#endif /* Mask_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef NXlibint_H
#define NXlibint_H
#ifdef __cplusplus
extern "C" {
#endif
#include "NXvars.h"
#ifdef __cplusplus
}
#endif
#endif /* NXlibint_H */
This diff is collapsed. Click to expand it.
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Pgn_H
#define Pgn_H
#ifdef __cplusplus
extern "C" {
#endif
#include "X11/X.h"
#include "X11/Xlib.h"
#include "X11/Xmd.h"
#include <png.h>
extern int PngCompareColorTable(
#if NeedFunctionPrototypes
NXColorTable* /* color_table_1 */,
NXColorTable* /* color_table_2 */
#endif
);
extern char *PngCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
int* /* compressed_size */
#endif
);
int NXCreatePalette16(
#if NeedFunctionPrototypes
XImage* /* src_image */,
NXColorTable* /* color_table */,
CARD8* /* image_index */,
int /* nb_max */
#endif
);
int NXCreatePalette32(
#if NeedFunctionPrototypes
XImage* /* src_image */,
NXColorTable* /* color_table */,
CARD8* /* image_index */,
int /* nb_max */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Pgn_H */
README
------
1. To compile:
> tar zxvf nxcompext-X.Y.Z-N.tar.gz
> cd nxcompext
> ./configure
> make
You'll have to run gmake under Solaris.
2. The 'make install' target is not currently supported
in the Makefile, but it should be simple to fix.
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <zlib.h>
#include "NXlib.h"
#include "Rgb.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define RGB_COMPRESSION_LEVEL 4
#define RGB_COMPRESSION_THRESHOLD 32
#define RGB_COMPRESSION_STRATEGY Z_DEFAULT_STRATEGY
static int rgbCompressionLevel = RGB_COMPRESSION_LEVEL;
static int rgbCompressionThreshold = RGB_COMPRESSION_THRESHOLD;
static int rgbCompressionStrategy = RGB_COMPRESSION_STRATEGY;
char *RgbCompressData(XImage *image, unsigned int *size)
{
return ZCompressData(image -> data, image -> bytes_per_line * image -> height,
rgbCompressionThreshold, rgbCompressionLevel,
rgbCompressionStrategy, size);
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Rgb_H
#define Rgb_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *RgbCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Rgb_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <zlib.h>
#include "NXlib.h"
#include "Rle.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define RLE_COMPRESSION_LEVEL 1
#define RLE_COMPRESSION_THRESHOLD 32
#define RLE_COMPRESSION_STRATEGY Z_RLE
static int rleCompressionLevel = RLE_COMPRESSION_LEVEL;
static int rleCompressionThreshold = RLE_COMPRESSION_THRESHOLD;
static int rleCompressionStrategy = RLE_COMPRESSION_STRATEGY;
char *RleCompressData(XImage *image, unsigned int *size)
{
return ZCompressData(image -> data, image -> bytes_per_line * image -> height,
rleCompressionThreshold, rleCompressionLevel,
rleCompressionStrategy, size);
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Rle_H
#define Rle_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *RleCompressData(
#if NeedFunctionPrototypes
XImage* /* image */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Rle_H */
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#include "NXlib.h"
#include "Z.h"
#define PANIC
#define WARNING
#undef TEST
#undef DEBUG
#define Z_COMPRESSION_LEVEL 4
#define Z_COMPRESSION_THRESHOLD 32
#define Z_COMPRESSION_STRATEGY Z_DEFAULT_STRATEGY
static int zCompressionLevel = Z_COMPRESSION_LEVEL;
static int zCompressionStrategy = Z_COMPRESSION_STRATEGY;
static z_stream *zStream;
static int zInitialized;
static int ZConfigure(int level, int strategy);
static int ZDeflate(char *dest, unsigned int *destLen,
const char *source, unsigned int sourceLen);
char *ZCompressData(const char *plainData, unsigned int plainSize, int threshold,
int level, int strategy, unsigned int *compressedSize)
{
char *compressedData;
/*
* Determine the size of the source image
* data and make sure there is enough
* space in the destination buffer.
*/
*compressedSize = plainSize + (plainSize / 1000) + 12 + 1;
compressedData = Xmalloc(*compressedSize);
if (compressedData == NULL)
{
#ifdef PANIC
fprintf(stderr, "******ZCompressData: PANIC! Failed to allocate [%d] bytes for the destination.\n",
*compressedSize);
#endif
*compressedSize = 0;
return NULL;
}
if (level == Z_NO_COMPRESSION || plainSize < threshold)
{
#ifdef TEST
fprintf(stderr, "******ZCompressData: Not compressing [%d] bytes with level [%d] and "
"threshold [%d].\n", plainSize, level, threshold);
#endif
/*
* Tell in the first byte of the buffer
* if the remaining data is compressed
* or not. This same byte can be used
* in future to store some other flag.
*/
*compressedData = 0;
memcpy(compressedData + 1, plainData, plainSize);
*compressedSize = plainSize + 1;
return compressedData;
}
else
{
int result;
/*
* Reconfigure the stream if needed.
*/
if (zCompressionLevel != level ||
zCompressionStrategy != strategy)
{
ZConfigure(level, strategy);
zCompressionLevel = level;
zCompressionStrategy = strategy;
}
result = ZDeflate(compressedData + 1, compressedSize, plainData, plainSize);
if (result != Z_OK)
{
#ifdef PANIC
fprintf(stderr, "******ZCompressData: PANIC! Failed to compress [%d] bytes with error [%s].\n",
plainSize, zError(result));
#endif
Xfree(compressedData);
*compressedSize = 0;
return NULL;
}
#ifdef TEST
fprintf(stderr, "******ZCompressData: Source data of [%d] bytes compressed to [%d].\n",
plainSize, *compressedSize);
#endif
*compressedData = 1;
*compressedSize = *compressedSize + 1;
return compressedData;
}
}
int ZConfigure(int level, int strategy)
{
/*
* ZLIB wants the avail_out to be
* non zero, even if the stream was
* already flushed.
*/
unsigned char dest[1];
zStream -> next_out = dest;
zStream -> avail_out = 1;
if (deflateParams(zStream, level, strategy) != Z_OK)
{
#ifdef PANIC
fprintf(stderr, "******ZConfigure: PANIC! Failed to set level to [%d] and strategy to [%d].\n",
level, strategy);
#endif
return -1;
}
#ifdef TEST
else
{
fprintf(stderr, "******ZConfigure: Reconfigured the stream with level [%d] and strategy [%d].\n",
level, strategy);
}
#endif
return 1;
}
int ZDeflate(char *dest, unsigned int *destLen, const char *source, unsigned int sourceLen)
{
int saveOut;
int result;
/*
* Deal with the possible overflow.
*/
if (zStream -> total_out & 0x80000000)
{
#ifdef TEST
fprintf(stderr, "******ZDeflate: Reset Z stream counters with total in [%ld] total out [%ld].\n",
zStream -> total_in, zStream -> total_out);
#endif
zStream -> total_in = 0;
zStream -> total_out = 0;
}
saveOut = zStream -> total_out;
zStream -> next_in = (Bytef *) source;
zStream -> avail_in = (uInt) sourceLen;
#ifdef MAXSEG_64K
/*
* Check if the source is greater
* than 64K on a 16-bit machine.
*/
if ((uLong) zStream -> avail_in != sourceLen) return Z_BUF_ERROR;
#endif
zStream -> next_out = (unsigned char *) dest;
zStream -> avail_out = (uInt) *destLen;
if ((uLong) zStream -> avail_out != *destLen) return Z_BUF_ERROR;
result = deflate(zStream, Z_FINISH);
if (result != Z_STREAM_END)
{
deflateReset(zStream);
return (result == Z_OK ? Z_BUF_ERROR : result);
}
*destLen = zStream -> total_out - saveOut;
result = deflateReset(zStream);
return result;
}
int ZInitEncoder()
{
if (zInitialized == 0)
{
int result;
zStream = Xmalloc(sizeof(z_stream));
if (zStream == NULL)
{
#ifdef PANIC
fprintf(stderr, "******ZInitEncoder: PANIC! Failed to allocate memory for the stream.\n");
#endif
return -1;
}
zStream -> zalloc = (alloc_func) 0;
zStream -> zfree = (free_func) 0;
zStream -> opaque = (voidpf) 0;
#ifdef TEST
fprintf(stderr, "******ZInitEncoder: Initializing compressor with level [%d] and startegy [%d].\n",
zCompressionLevel, zCompressionStrategy);
#endif
result = deflateInit2(zStream, zCompressionLevel, Z_DEFLATED,
15, 9, zCompressionStrategy);
if (result != Z_OK)
{
#ifdef PANIC
fprintf(stderr, "******ZInitEncoder: Failed to initialize the compressor with error [%s].\n",
zError(result));
#endif
return -1;
}
zInitialized = 1;
}
return zInitialized;
}
int ZResetEncoder()
{
int result;
if (zInitialized == 1)
{
result = deflateEnd(zStream);
if (result != Z_OK)
{
#ifdef WARNING
fprintf(stderr, "******ZResetEncoder: WARNING! Failed to deinitialize the compressor with error [%s].\n",
zError(result));
#endif
}
Xfree(zStream);
}
zInitialized = 0;
return 1;
}
/**************************************************************************/
/* */
/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */
/* */
/* NXCOMPEXT, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present */
/* software is allowed according to terms specified in the file LICENSE */
/* which comes in the source distribution. */
/* */
/* Check http://www.nomachine.com/licensing.html for applicability. */
/* */
/* NX and NoMachine are trademarks of NoMachine S.r.l. */
/* */
/* All rigths reserved. */
/* */
/**************************************************************************/
#ifndef Z_H
#define Z_H
#ifdef __cplusplus
extern "C" {
#endif
int ZInitEncoder(
#if NeedFunctionPrototypes
void
#endif
);
int ZResetEncoder(
#if NeedFunctionPrototypes
void
#endif
);
extern char *ZCompressData(
#if NeedFunctionPrototypes
const char* /* data */,
unsigned int /* size */,
int /* threshold */,
int /* level */,
int /* strategy */,
unsigned int* /* compressed_size */
#endif
);
#ifdef __cplusplus
}
#endif
#endif /* Z_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
dnl Process this file with autoconf to produce a configure script.
dnl Prolog
AC_INIT(NXlib.h)
AC_PREREQ(2.13)
dnl Reset default compilation flags.
CXXFLAGS="-O3"
CFLAGS="-O3"
dnl Reset default linking directives.
LIBSTATIC=""
LIBSHARED=""
dnl Prefer headers and libraries from nx-X11, if present.
if test -d "../nx-X11/include" ; then
CXXFLAGS="$CXXFLAGS -I../nx-X11/exports/include -I../nx-X11/lib/X11 \
-I../nx-X11/include -I../nx-X11/programs/Xserver/include"
CFLAGS="$CFLAGS -I../nx-X11/exports/include -I../nx-X11/lib/X11 \
-I../nx-X11/include -I../nx-X11/programs/Xserver/include"
LDFLAGS="$LDFLAGS -L../nx-X11/exports/lib"
fi
dnl Check for programs.
AC_PROG_CXX
AC_PROG_CC
AC_LANG_CPLUSPLUS
dnl Check for BSD compatible install.
AC_PROG_INSTALL
dnl Check for extra header files.
AC_PATH_XTRA
dnl Custom addition.
ac_help="$ac_help
--with-symbols add the -g flag to produce the debug symbols
--with-info enable basic log output to trace the program
--with-valgrind clean up allocated buffers to avoid valgrind warnings
--with-version use this version for produced libraries
--with-static-png enable static linking of PNG library
--with-static-jpeg enable static linking of JPEG library"
dnl Check to see if we're running under Cygwin32.
AC_DEFUN(nxproxy_CYGWIN32,
[AC_CACHE_CHECK(for Cygwin32 environment, nxproxy_cv_cygwin32,
[AC_TRY_COMPILE(,[return __CYGWIN32__;],
nxproxy_cv_cygwin32=yes, nxproxy_cv_cygwin32=no)
rm -f conftest*])
CYGWIN32=
test "$nxproxy_cv_cygwin32" = yes && CYGWIN32=yes])
dnl CygWin32 requires the stdc++ library explicitly linked.
nxproxy_CYGWIN32
if test "$CYGWIN32" = yes; then
LIBS="$LIBS -mwindows -lstdc++"
fi
dnl Check whether we're building on a AMD64.
AC_DEFUN(nxconf_AMD64,
[AC_CACHE_CHECK(for Amd64 environment, nxconf_cv_amd64,
[AC_TRY_COMPILE(,[return (__amd64__ || __x86_64__);],
nxconf_cv_amd64=yes, nxconf_cv_amd64=no)
rm -f conftest*])
AMD64=
test "$nxconf_cv_amd64" = yes && AMD64=yes])
nxconf_AMD64
dnl Check to see if we're running under Solaris.
AC_DEFUN(nxconf_SUN,
[AC_CACHE_CHECK(for SunOS environment, nxconf_cv_sun,
[AC_TRY_COMPILE(,[return __sun;],
nxconf_cv_sun=yes, nxconf_cv_sun=no)
rm -f conftest*])
SUN=
test "$nxconf_cv_sun" = yes && SUN=yes])
nxconf_SUN
if test "$SUN" = yes; then
CFLAGS="$CFLAGS -I/usr/sfw/include"
fi
if test "$SUN" = yes; then
LDFLAGS="$LDFLAGS -G -h \$(LIBLOAD) -L/usr/sfw/lib"
else
LDFLAGS="$LDFLAGS -shared -Wl,-soname,\$(LIBLOAD)"
fi
dnl Check to see if we're running under FreeBSD.
AC_DEFUN(nxconf_FreeBSD,
[AC_CACHE_CHECK(for FreeBSD environment, nxconf_cv_freebsd,
[AC_TRY_COMPILE(,[return __FreeBSD__;],
nxconf_cv_freebsd=yes, nxconf_cv_freebsd=no)
rm -f conftest*])
FreeBSD=
test "$nxconf_cv_freebsd" = yes && FreeBSD=yes])
nxconf_FreeBSD
dnl Build PIC libraries.
if test "$CYGWIN32" != yes -a "$DARWIN" != yes; then
CXXFLAGS="$CXXFLAGS -fPIC"
CFLAGS="$CFLAGS -fPIC"
fi
dnl On FreeBSD search libraries and includes under /usr/local.
if test "$FreeBSD" = yes; then
LIBS="$LIBS -L/usr/local/lib"
CXXFLAGS="$CXXFLAGS -I/usr/local/include"
CFLAGS="$CFLAGS -I/usr/local/include"
fi
dnl Check whether --with-static-png was
dnl given and add -lpng or libpng.a to linking.
if test "${with_static_png}" = yes; then
echo -e "enabling static linking of PNG library"
if test "$CYGWIN32" = yes; then
LIBS="$LIBSTATIC -static -lpng"
else
if test -f "/usr/lib/libpng.a" ; then
LIBS="/usr/lib/libpng.a $LIBS"
else
if test -f "/usr/local/lib/libpng.a" ; then
echo -e "assuming libpng.a in /usr/local/lib"
LIBS="/usr/local/lib/libpng.a $LIBS"
else
echo -e "assuming libpng.a in default linker path"
LIBS="libpng.a $LIBS"
fi
fi
fi
else
echo -e "enabling dynamic linking of PNG library"
LIBS="-lpng $LIBS"
fi
dnl Check whether --with-static-jpeg was
dnl given and add -ljpeg or libjpeg.a to linking.
if test "${with_static_jpeg}" = yes; then
echo -e "enabling static linking of JPEG library"
if test "$CYGWIN32" = yes; then
LIBSTATIC="$LIBS -static -ljpeg"
else
if test -f "/usr/lib/libjpeg.a" ; then
LIBS="/usr/lib/libjpeg.a $LIBS"
else
if test -f "/usr/local/lib/libjpeg.a" ; then
echo -e "assuming libjpeg.a in /usr/local/lib"
LIBS="/usr/local/lib/libjpeg.a $LIBS"
else
echo -e "assuming libjpeg.a in default linker path"
LIBS="libjpeg.a $LIBS"
fi
fi
fi
else
echo -e "enabling dynamic linking of JPEG library"
LIBS="-ljpeg $LIBS"
fi
dnl Check whether --with-symbols or --without-symbols was
dnl given and set the required optimization level.
if test "${with_symbols}" = yes; then
echo -e "enabling production of debug symbols"
CXXFLAGS="-g $CXXFLAGS"
CFLAGS="-g $CFLAGS"
else
echo -e "disabling production of debug symbols"
fi
dnl Check whether --with-info or --without-info was given.
if test "${with_info}" = yes; then
echo -e "enabling info output in the log file"
CXXFLAGS="$CXXFLAGS -DINFO"
CFLAGS="$CFLAGS -DINFO"
else
echo -e "disabling info output in the log file"
fi
dnl Check whether --with-valgrind or --without-valgrind was given.
if test "${with_valgrind}" = yes; then
echo -e "enabling valgrind memory checker workarounds"
CXXFLAGS="$CXXFLAGS -DVALGRIND"
CFLAGS="$CFLAGS -DVALGRIND"
else
echo -e "disabling valgrind memory checker workarounds"
fi
dnl Check whether --with-version was given.
AC_SUBST(LIBVERSION)
AC_SUBST(VERSION)
if test "${with_version}" = yes; then
VERSION=${ac_option}
else
VERSION=`cat VERSION`
fi
echo -e "compiling version ${VERSION}"
LIBVERSION=`echo ${VERSION} | cut -d '.' -f 1`
CXXFLAGS="$CXXFLAGS -DVERSION=\\\"${VERSION}\\\""
CFLAGS="$CFLAGS -DVERSION=\\\"${VERSION}\\\""
dnl Find makedepend somewhere.
AC_SUBST(MAKEDEPEND)
if test -x "../nx-X11/config/makedepend/makedepend" ; then
MAKEDEPEND=../nx-X11/config/makedepend/makedepend
else
if test -x "/usr/X11R6/bin/makedepend" ; then
MAKEDEPEND=/usr/X11R6/bin/makedepend
else
if test -x "/usr/openwin/bin/makedepend" ; then
MAKEDEPEND=/usr/openwin/bin/makedepend
else
MAKEDEPEND=/usr/bin/makedepend
fi
fi
fi
dnl Determine what to build based on the platform.
dnl Override the LIBS settings on Cygwin32 so that
dnl we always link with the exact set of libraries.
AC_SUBST(ALL)
if test "$CYGWIN32" = yes; then
ALL="\$(LIBCYGARCHIVE) \$(LIBCYGSHARED) \$(LIBARCHIVE)"
else
ALL="\$(LIBFULL) \$(LIBLOAD) \$(LIBSHARED) \$(LIBARCHIVE)"
fi
AC_OUTPUT(Makefile)
#! /bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Last modified: 1995-03-05
# Public domain
errstatus=0
for file in ${1+"$@"} ; do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d in ${1+"$@"} ; do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp" 1>&2
mkdir "$pathcomp" > /dev/null 2>&1 || lasterr=$?
fi
if test ! -d "$pathcomp"; then
errstatus=$lasterr
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment