New mailsend sources
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
##
|
||||
# Makefile Generated by genmake 1.0, Nov-16-96
|
||||
# genmake 1.0 by ma_muquit@fccc.edu, RCS
|
||||
##
|
||||
CC= @CC@
|
||||
DEFS= @DEFS@
|
||||
AR= ar cq
|
||||
RANLIB= @RANLIB@
|
||||
LIBNAME= libmsock.a
|
||||
|
||||
OPENSSL_DIR=@OPENSSL_DIR@
|
||||
OPENSSL_INC=@OPENSSL_INC@
|
||||
OPENSSL_LIBS=@OPENSSL_LIBS@
|
||||
|
||||
INCLUDES= -I. $(OPENSSL_INC)
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DSYS_UNIX=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
|
||||
SRCS = msock.c
|
||||
|
||||
OBJS = msock.o
|
||||
|
||||
.c.o:
|
||||
rm -f $@
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
all: $(LIBNAME)
|
||||
|
||||
$(LIBNAME) : $(OBJS)
|
||||
rm -f $@
|
||||
$(AR) $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(LIBNAME) core
|
||||
|
||||
clean_all:
|
||||
make clean
|
||||
(cd examples/htget; make clean)
|
||||
(cd examples/echod; make clean)
|
||||
(cd examples/server_type; make clean)
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#--------------------------------------------
|
||||
# Makefile for MS Visual C++
|
||||
# muquit@muquit.com
|
||||
# Updated for MS Visual Studio 10.0 Feb-27-2012
|
||||
#--------------------------------------------
|
||||
|
||||
CFLAGS= /DWINNT /DWIN32 /DHAVE_MALLOC_H /DHAVE_OPENSSL /DHAVE_GETADDRINFO=1 /Ic:\openssl\include /I.
|
||||
#CFLAGS= /DWINNT /DWIN32 /DHAVE_MALLOC_H /DHAVE_OPENSSL /Ic:\openssl\include /I.
|
||||
CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo
|
||||
LIBFLAGS=/nologo
|
||||
LIBRARY=msock.lib
|
||||
|
||||
SRCS = msock.c
|
||||
OBJS = msock.obj
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
lib $(LIBFLAGS) $(OBJS) /out:$(LIBRARY)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(LIBRARY) *.bak
|
||||
@@ -0,0 +1,35 @@
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#define EALREADY WSAEALREADY
|
||||
#define ENOTSOCK WSAENOTSOCK
|
||||
#define EDESTADDRREQ WSAEDESTADDRREQ
|
||||
#define EMSGSIZE WSAEMSGSIZE
|
||||
#define EPROTOTYPE WSAEPROTOTYPE
|
||||
#define ENOPROTOOPT WSAENOPROTOOPT
|
||||
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
||||
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
|
||||
#define EOPNOTSUPP WSAEOPNOTSUPP
|
||||
#define EPFNOSUPPORT WSAEPFNOSUPPORT
|
||||
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
||||
#define EADDRINUSE WSAEADDRINUSE
|
||||
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
|
||||
#define ENETDOWN WSAENETDOWN
|
||||
#define ENETUNREACH WSAENETUNREACH
|
||||
#define ENETRESET WSAENETRESET
|
||||
#define ECONNABORTED WSAECONNABORTED
|
||||
#define ECONNRESET WSAECONNRESET
|
||||
#define ENOBUFS WSAENOBUFS
|
||||
#define EISCONN WSAEISCONN
|
||||
#define ENOTCONN WSAENOTCONN
|
||||
#define ESHUTDOWN WSAESHUTDOWN
|
||||
#define ETOOMANYREFS WSAETOOMANYREFS
|
||||
#define ETIMEDOUT WSAETIMEDOUT
|
||||
#define ECONNREFUSED WSAECONNREFUSED
|
||||
#define ELOOP WSAELOOP
|
||||
#define EHOSTDOWN WSAEHOSTDOWN
|
||||
#define EHOSTUNREACH WSAEHOSTUNREACH
|
||||
#define EPROCLIM WSAEPROCLIM
|
||||
#define EUSERS WSAEUSERS
|
||||
#define EDQUOT WSAEDQUOT
|
||||
#define ESTALE WSAESTALE
|
||||
#define EREMOTE WSAEREMOTE
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#--------------------------------------------
|
||||
# Makefile for MS Visual C++
|
||||
# muquit@muquit.com
|
||||
#--------------------------------------------
|
||||
|
||||
CC= cl /MD
|
||||
OPENSSL_DIR=c:\openssl
|
||||
OPENSSL_INC=-I$(OPENSSL_DIR)/include
|
||||
OPENSSL_LIBS=$(OPENSSL_DIR)/lib/libeay32.lib $(OPENSSL_DIR)/lib/ssleay32.lib
|
||||
|
||||
DEFS= -DWINNT=1 -DSTRICT_MODE=1 -DHAVE_STRING_H=1 -DHAVE_FCNTL_H=1 -DHAVE_OPENSSL=1
|
||||
|
||||
INCLUDES= -I. $(OPENSSL_INC)
|
||||
LIBRARY=msock.lib
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS)
|
||||
#CFLAGS= $(cvars) $(cdebug) -nologo -G4 $(DEFINES)
|
||||
CFLAGS= $(DEFINES)
|
||||
|
||||
SRCS = msock.c
|
||||
OBJS = msock.obj
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c $< -Fo$@
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
link /lib /OUT:$(LIBRARY) $(OBJS)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(LIBRARY) *.bak
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env ruby
|
||||
# muquit@muquit.com Aug-26-2012
|
||||
begin
|
||||
t = Time.new
|
||||
puts <<EOD
|
||||
\#ifndef WERRNO_H
|
||||
\#define WERRNO_H
|
||||
|
||||
\#ifdef WINNT
|
||||
|
||||
/*
|
||||
** This file is auto generated on #{t}
|
||||
** Map wisock error code. Newer Visual Studio defines them
|
||||
** but they do not map to Winsock error code.
|
||||
*/
|
||||
EOD
|
||||
|
||||
lines = File.read("./ecode.txt")
|
||||
|
||||
lines.each do |l|
|
||||
l = l.strip
|
||||
if l =~ /#define (.*)\s+(.*)$/
|
||||
d = $1.strip
|
||||
puts <<EOD
|
||||
\#undef #{d}
|
||||
#{l}
|
||||
|
||||
EOD
|
||||
end
|
||||
end
|
||||
puts <<EOD
|
||||
\#endif /* WINNT */
|
||||
|
||||
\#endif /* WERRNO_H */
|
||||
EOD
|
||||
end
|
||||
@@ -0,0 +1,118 @@
|
||||
#ifndef WERRNO_H
|
||||
#define WERRNO_H
|
||||
|
||||
#ifdef WINNT
|
||||
|
||||
/*
|
||||
** This file is auto generated on Sun Aug 26 10:12:25 -0400 2012
|
||||
** Map wisock error code. Newer Visual Studio defines them
|
||||
** but they do not map to Winsock error code.
|
||||
*/
|
||||
#undef EWOULDBLOCK
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
|
||||
#undef EINPROGRESS
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
|
||||
#undef EALREADY
|
||||
#define EALREADY WSAEALREADY
|
||||
|
||||
#undef ENOTSOCK
|
||||
#define ENOTSOCK WSAENOTSOCK
|
||||
|
||||
#undef EDESTADDRREQ
|
||||
#define EDESTADDRREQ WSAEDESTADDRREQ
|
||||
|
||||
#undef EMSGSIZE
|
||||
#define EMSGSIZE WSAEMSGSIZE
|
||||
|
||||
#undef EPROTOTYPE
|
||||
#define EPROTOTYPE WSAEPROTOTYPE
|
||||
|
||||
#undef ENOPROTOOPT
|
||||
#define ENOPROTOOPT WSAENOPROTOOPT
|
||||
|
||||
#undef EPROTONOSUPPORT
|
||||
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
||||
|
||||
#undef ESOCKTNOSUPPORT
|
||||
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
|
||||
|
||||
#undef EOPNOTSUPP
|
||||
#define EOPNOTSUPP WSAEOPNOTSUPP
|
||||
|
||||
#undef EPFNOSUPPORT
|
||||
#define EPFNOSUPPORT WSAEPFNOSUPPORT
|
||||
|
||||
#undef EAFNOSUPPORT
|
||||
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
||||
|
||||
#undef EADDRINUSE
|
||||
#define EADDRINUSE WSAEADDRINUSE
|
||||
|
||||
#undef EADDRNOTAVAIL
|
||||
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
|
||||
|
||||
#undef ENETDOWN
|
||||
#define ENETDOWN WSAENETDOWN
|
||||
|
||||
#undef ENETUNREACH
|
||||
#define ENETUNREACH WSAENETUNREACH
|
||||
|
||||
#undef ENETRESET
|
||||
#define ENETRESET WSAENETRESET
|
||||
|
||||
#undef ECONNABORTED
|
||||
#define ECONNABORTED WSAECONNABORTED
|
||||
|
||||
#undef ECONNRESET
|
||||
#define ECONNRESET WSAECONNRESET
|
||||
|
||||
#undef ENOBUFS
|
||||
#define ENOBUFS WSAENOBUFS
|
||||
|
||||
#undef EISCONN
|
||||
#define EISCONN WSAEISCONN
|
||||
|
||||
#undef ENOTCONN
|
||||
#define ENOTCONN WSAENOTCONN
|
||||
|
||||
#undef ESHUTDOWN
|
||||
#define ESHUTDOWN WSAESHUTDOWN
|
||||
|
||||
#undef ETOOMANYREFS
|
||||
#define ETOOMANYREFS WSAETOOMANYREFS
|
||||
|
||||
#undef ETIMEDOUT
|
||||
#define ETIMEDOUT WSAETIMEDOUT
|
||||
|
||||
#undef ECONNREFUSED
|
||||
#define ECONNREFUSED WSAECONNREFUSED
|
||||
|
||||
#undef ELOOP
|
||||
#define ELOOP WSAELOOP
|
||||
|
||||
#undef EHOSTDOWN
|
||||
#define EHOSTDOWN WSAEHOSTDOWN
|
||||
|
||||
#undef EHOSTUNREACH
|
||||
#define EHOSTUNREACH WSAEHOSTUNREACH
|
||||
|
||||
#undef EPROCLIM
|
||||
#define EPROCLIM WSAEPROCLIM
|
||||
|
||||
#undef EUSERS
|
||||
#define EUSERS WSAEUSERS
|
||||
|
||||
#undef EDQUOT
|
||||
#define EDQUOT WSAEDQUOT
|
||||
|
||||
#undef ESTALE
|
||||
#define ESTALE WSAESTALE
|
||||
|
||||
#undef EREMOTE
|
||||
#define EREMOTE WSAEREMOTE
|
||||
|
||||
#endif /* WINNT */
|
||||
|
||||
#endif /* WERRNO_H */
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
# jul-29-1999
|
||||
|
||||
CC= @CC@
|
||||
DEFS= @DEFS@
|
||||
AR= ar cq
|
||||
RANLIB= @RANLIB@
|
||||
LIBNAME= libmutils.a
|
||||
|
||||
OPENSSL_DIR=@OPENSSL_DIR@
|
||||
OPENSSL_INC=@OPENSSL_INC@
|
||||
OPENSSL_LIBS=@OPENSSL_LIBS@ @DL_LIB@
|
||||
|
||||
INCLUDES= -I. $(OPENSSL_INC)
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DSYS_UNIX=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
|
||||
SRCS = string.c mutils.c mutils_mime.c mutils_blob.c \
|
||||
mutils_error.c mutils_temp.c mutils_time.c
|
||||
OBJS = string.o mutils.o mutils_mime.o mutils_blob.o \
|
||||
mutils_error.o mutils_temp.o mutils_time.o
|
||||
|
||||
.c.o:
|
||||
rm -f $@
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
all: $(LIBNAME)
|
||||
|
||||
$(LIBNAME): $(OBJS)
|
||||
rm -f $@
|
||||
$(AR) $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(LIBNAME) core
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#--------------------------------------------
|
||||
# Makefile for MS Visual C++
|
||||
# muquit@muquit.com
|
||||
# updated for MS Visual Studio 10.0 Feb-27-2012
|
||||
#--------------------------------------------
|
||||
|
||||
OPENSSL_DIR=c:/openssl
|
||||
OPENSSL_INC=/I$(OPENSSL_DIR)/include
|
||||
|
||||
CFLAGS= /DWINNT /DWIN32 /DHAVE_MALLOC_H /DHAVE_STRING_H /DHAVE_FCNTL_H /DHAVE_CTYPE_H /DHAVE_STDLIB_H /DHAVE_OPENSSL /I. $(OPENSSL_INC)
|
||||
CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo
|
||||
LIBFLAGS=/nologo
|
||||
LIBRARY=mutils.lib
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS)
|
||||
#CFLAGS= $(cvars) $(cdebug) -nologo -G4 $(DEFINES)
|
||||
|
||||
|
||||
SRCS = string.c mutils.c muilts_mime.c mutils_error.c mutils_blob.c \
|
||||
mutils_temp.c mutils_time.c
|
||||
OBJS = string.obj mutils.obj mutils_mime.obj mutils_error.obj mutils_blob.obj \
|
||||
mutils_temp.obj mutils_time.obj
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
lib $(LIBFLAGS) $(OBJS) /out:$(LIBRARY)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(LIBRARY) *.bak
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#--------------------------------------------
|
||||
# Makefile for MS Visual C++
|
||||
# ma_muquit@fccc.edu
|
||||
# Jan-09-1999, Saturday, for Count 2.5
|
||||
# Aug-08-1999
|
||||
#--------------------------------------------
|
||||
|
||||
CC= cl /MD
|
||||
DEFS= -DWINNT=1 -DSTRICT_MODE=1 -DHAVE_STRING_H=1 -DHAVE_FCNTL_H=1 -DHAVE_STDLIB_H=1
|
||||
|
||||
INCLUDES= -I. -I..
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS)
|
||||
CFLAGS= $(cvars) $(cdebug) -nologo -G4 $(DEFINES)
|
||||
|
||||
SRCS = string.c mutils.c mime.c
|
||||
OBJS = string.obj mutils.obj mime.obj
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c $< -Fo$@
|
||||
|
||||
all: utils.lib
|
||||
|
||||
utils.lib: $(OBJS)
|
||||
link /lib /OUT:mutils.lib $(OBJS)
|
||||
|
||||
utils.obj: mutils.h
|
||||
|
||||
clean:
|
||||
del $(OBJS) mutils.lib *.bak
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
** mkey_hex and iv are generated at compile time
|
||||
**
|
||||
** muquit@muquit.com May-14-2012
|
||||
*/
|
||||
#include "mutils.h"
|
||||
|
||||
#define MKEY_HEX_LENGTH 48
|
||||
#define IV_HEX_LENGTH 8
|
||||
|
||||
/* master key and iv are generated on: @MKEY_GENERATED@ */
|
||||
/* -- GENERATED CODE: do not modify stats -- */
|
||||
static char *mkey_hex="@MKEY_HEX@";
|
||||
static char *iv_hex="@IV_HEX@";
|
||||
/* -- GENERATED CODE: do not modify ends -- */
|
||||
|
||||
/*
|
||||
** Return a 24 byte binary data.
|
||||
*/
|
||||
unsigned char *mutils_get_master_key24(void)
|
||||
{
|
||||
unsigned char
|
||||
*bin = NULL;
|
||||
|
||||
int
|
||||
olen;
|
||||
|
||||
char
|
||||
*hex,
|
||||
*default_mkey_hex;
|
||||
|
||||
default_mkey_hex="cfed17bd5ca36d94bfb77e029a2d0c876f6d0cc2bc8a53d6";
|
||||
if (mkey_hex && strlen(mkey_hex) == MKEY_HEX_LENGTH)
|
||||
{
|
||||
hex = mkey_hex;
|
||||
}
|
||||
else
|
||||
{
|
||||
hex = default_mkey_hex;
|
||||
}
|
||||
bin = mutils_hex_to_bin(hex, MKEY_HEX_LENGTH, &olen);
|
||||
if (olen > 0)
|
||||
return(bin);
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
** Returns a 8 byte binary data
|
||||
*/
|
||||
unsigned char *mutils_get_iv8(void)
|
||||
{
|
||||
unsigned char
|
||||
*bin = NULL;
|
||||
|
||||
int
|
||||
olen;
|
||||
|
||||
char
|
||||
*hex,
|
||||
*default_iv_hex;
|
||||
|
||||
default_iv_hex="f76f9c327947ee19";
|
||||
if (iv_hex && strlen(iv_hex) == IV_HEX_LENGTH)
|
||||
{
|
||||
hex = iv_hex;
|
||||
}
|
||||
else
|
||||
{
|
||||
hex = default_iv_hex;
|
||||
}
|
||||
bin = mutils_hex_to_bin(hex, IV_HEX_LENGTH, &olen);
|
||||
if (olen > 0)
|
||||
return(bin);
|
||||
return(NULL);
|
||||
}
|
||||
+692
@@ -0,0 +1,692 @@
|
||||
#include "mutils.h"
|
||||
|
||||
/* Note: all the blob realated routines are adapted from ImageMagick */
|
||||
|
||||
/*
|
||||
** attaches a blob to the MutilsBlob structure
|
||||
*/
|
||||
void mutils_attach_blob(MutilsBlob *blob_info,void *blob,size_t length)
|
||||
{
|
||||
if (blob == (MutilsBlob *) NULL)
|
||||
return;
|
||||
|
||||
blob_info->data=(unsigned char *) blob;
|
||||
blob_info->length=length;
|
||||
blob_info->offset=0;
|
||||
}
|
||||
|
||||
/* duplicate the given MutilsBlob structure */
|
||||
/* returns NULL on failure */
|
||||
/**
|
||||
* @brief Duplicates the given blob
|
||||
* @param blob Blob to duplicate
|
||||
* @return blob The duplicated blob on success, NULL on failure
|
||||
*
|
||||
*/
|
||||
MutilsBlob *mutils_clone_blobinfo(MutilsBlob *blob)
|
||||
{
|
||||
MutilsBlob
|
||||
*clone_info;
|
||||
|
||||
clone_info=(MutilsBlob *) mutils_acquire_memory(sizeof(MutilsBlob));
|
||||
if (clone_info == (MutilsBlob *) NULL)
|
||||
{
|
||||
mutils_error("%s (%d) - unable to clone MutilsBlob, memory allocation failed\n",MUTILS_CFL);
|
||||
return(NULL);
|
||||
}
|
||||
if (blob == (MutilsBlob *) NULL)
|
||||
{
|
||||
memset(clone_info,0,sizeof(MutilsBlob));
|
||||
return(clone_info);
|
||||
}
|
||||
|
||||
*clone_info=(*blob);
|
||||
return(clone_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief rewind a blob
|
||||
* @param blob
|
||||
*
|
||||
* Rewinds a blob after processing it
|
||||
*/
|
||||
void mutils_rewind_blob(MutilsBlob *blob)
|
||||
{
|
||||
if (!blob)
|
||||
return;
|
||||
blob->offset=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* allocate memory for blob and and the data member
|
||||
* @param data_len - the length of the data in bytes
|
||||
* @return - pointer to blob on SUCCESS, NULL on failure
|
||||
*/
|
||||
MutilsBlob *mutils_allocate_blob(int data_len)
|
||||
{
|
||||
MutilsBlob
|
||||
*blob=NULL;
|
||||
|
||||
if (data_len <= 0)
|
||||
return(NULL);
|
||||
|
||||
/* allocate memory for blob */
|
||||
blob=mutils_clone_blobinfo(NULL);
|
||||
if (blob == NULL)
|
||||
return(NULL);
|
||||
|
||||
/* allocate memory for data */
|
||||
blob->length=data_len;
|
||||
blob->data=(unsigned char *) mutils_acquire_memory(data_len+1);
|
||||
if (blob->data == NULL)
|
||||
{
|
||||
mutils_destroy_blob(blob);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(blob);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** detaches a blob from the BlobInfo structure.
|
||||
*/
|
||||
void mutils_detach_blob(MutilsBlob *blob)
|
||||
{
|
||||
if (blob == NULL)
|
||||
return;
|
||||
|
||||
blob->length=0;
|
||||
blob->offset=0;
|
||||
blob->data=(unsigned char *) NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a MutilsBlob object. allocates memory for data, copies the passed
|
||||
* data, update the length and returns the blob
|
||||
* @param data The data to copy to blob's data member
|
||||
* @param data_len The number of bytes of data
|
||||
* @return MutilsBlob on success NULL on failure
|
||||
*/
|
||||
MutilsBlob *mutils_data_to_blob(unsigned char *data,int data_len)
|
||||
{
|
||||
MutilsBlob
|
||||
*blob;
|
||||
|
||||
if (data == (unsigned char *) NULL)
|
||||
return(NULL);
|
||||
|
||||
blob=mutils_clone_blobinfo(NULL);
|
||||
if (blob == (MutilsBlob *) NULL)
|
||||
{
|
||||
(void) fprintf(stderr,"%s (%d) unable to create blob, memory allocation problem\n",__FILE__,__LINE__);
|
||||
return((MutilsBlob *) NULL);
|
||||
}
|
||||
blob->length=data_len;
|
||||
blob->data=(unsigned char *) mutils_acquire_memory(blob->length+1);
|
||||
if (blob->data == NULL)
|
||||
{
|
||||
(void) fprintf(stderr,"Unable to create blob data, memory allocation problem\n");
|
||||
mutils_destroy_blob(blob);
|
||||
return((void *) NULL);
|
||||
}
|
||||
|
||||
memcpy(blob->data,data,blob->length);
|
||||
|
||||
return(blob);
|
||||
}
|
||||
|
||||
/*
|
||||
** returns the contents of a file as a blob.
|
||||
** NULL on failure.
|
||||
*/
|
||||
MutilsBlob *mutils_file_to_blob(char *filename)
|
||||
{
|
||||
MutilsBlob
|
||||
*blob;
|
||||
|
||||
long
|
||||
count=0;
|
||||
|
||||
size_t
|
||||
length;
|
||||
|
||||
int
|
||||
fd;
|
||||
|
||||
struct stat
|
||||
statbuf;
|
||||
|
||||
if (filename == NULL)
|
||||
return(NULL);
|
||||
|
||||
fd=open(filename,O_RDONLY | O_BINARY);
|
||||
if (fd == -1)
|
||||
{
|
||||
(void) fprintf(stderr,"Unable to open file %s\n",filename);
|
||||
return((void *) NULL);
|
||||
}
|
||||
|
||||
length=(size_t) (fstat(fd,&statbuf)) < 0 ? 0 : statbuf.st_size;
|
||||
blob=mutils_clone_blobinfo(NULL);
|
||||
if (blob == (MutilsBlob *) NULL)
|
||||
{
|
||||
(void )close(fd);
|
||||
(void) fprintf(stderr,"unable to create blob, memory allocation problem\n");
|
||||
return((MutilsBlob *) NULL);
|
||||
}
|
||||
blob->length=length;
|
||||
blob->data=(unsigned char *) mutils_acquire_memory(blob->length+1);
|
||||
if (blob->data == NULL)
|
||||
{
|
||||
(void) fprintf(stderr,"Unable to create blob data, memory allocation problem\n");
|
||||
mutils_destroy_blob(blob);
|
||||
return((void *) NULL);
|
||||
}
|
||||
|
||||
count=read(fd,blob->data,length);
|
||||
(void) close(fd);
|
||||
|
||||
if ((size_t) count != length)
|
||||
{
|
||||
mutils_destroy_blob(blob);
|
||||
return((void *) NULL);
|
||||
}
|
||||
|
||||
return(blob);
|
||||
}
|
||||
|
||||
/*
|
||||
** deallocates memory associated with an BlobInfo structure
|
||||
*/
|
||||
void mutils_destroy_blob(MutilsBlob *blob)
|
||||
{
|
||||
if (blob == NULL)
|
||||
return;
|
||||
|
||||
if (blob->data)
|
||||
(void) free(blob->data);
|
||||
mutils_liberate_memory((void **) &blob);
|
||||
}
|
||||
|
||||
/*
|
||||
** converts a least-significant byte first buffer of integers to
|
||||
** most-significant byte first.
|
||||
*/
|
||||
void mutils_msb_order_long(char *p,const size_t length)
|
||||
{
|
||||
register char
|
||||
c,
|
||||
*q,
|
||||
*sp;
|
||||
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
q=p+length;
|
||||
while (p < q)
|
||||
{
|
||||
sp=p+3;
|
||||
c=(*sp);
|
||||
*sp=(*p);
|
||||
*p++=c;
|
||||
sp=p+1;
|
||||
c=(*sp);
|
||||
*sp=(*p);
|
||||
*p++=c;
|
||||
p+=2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** converts a least-significant byte first buffer of integers to
|
||||
** most-significant byte first.
|
||||
*/
|
||||
void mutils_msb_order_short(char *p,const size_t length)
|
||||
{
|
||||
register char
|
||||
c,
|
||||
*q;
|
||||
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
q=p+length;
|
||||
while (p < q)
|
||||
{
|
||||
c=(*p);
|
||||
*p=(*(p+1));
|
||||
p++;
|
||||
*p++=c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** reads data from the blob and returns it. It returns the number of bytes
|
||||
** read.
|
||||
** blob - MutilsBlob
|
||||
** length - number of bytes to read from blob
|
||||
** data - returns
|
||||
**
|
||||
** returns > 0 on sucess, -1 on failure
|
||||
*/
|
||||
int mutils_read_blob(MutilsBlob *blob,const size_t length,void *data)
|
||||
{
|
||||
int
|
||||
count,
|
||||
n=0;
|
||||
|
||||
if (blob == (MutilsBlob *) NULL)
|
||||
return(-1);
|
||||
|
||||
if (blob->data != (unsigned char *) NULL)
|
||||
{
|
||||
count=MUTILS_MIN(length,blob->length - blob->offset);
|
||||
if (count > 0)
|
||||
{
|
||||
(void) memcpy(data,blob->data + blob->offset,count);
|
||||
blob->offset += count;
|
||||
}
|
||||
/*
|
||||
if (count < length)
|
||||
return(-1);
|
||||
*/
|
||||
return(count);
|
||||
}
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
** reads a single byte from blob and returns it.
|
||||
** returns -1 on error
|
||||
*/
|
||||
int mutils_read_blob_byte(MutilsBlob *blob)
|
||||
{
|
||||
size_t
|
||||
count;
|
||||
|
||||
unsigned char
|
||||
buffer[1];
|
||||
|
||||
if (blob == NULL)
|
||||
return(-1);
|
||||
|
||||
count=mutils_read_blob(blob,1,(unsigned char *) buffer);
|
||||
if (count == 0)
|
||||
return(-1);
|
||||
|
||||
return(*buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
** reads a long value as a 32 bit quantity in least-significant byte first
|
||||
**order.
|
||||
*/
|
||||
unsigned long mutils_read_blob_lsb_long(MutilsBlob *blob)
|
||||
{
|
||||
unsigned char
|
||||
buffer[4];
|
||||
|
||||
unsigned long
|
||||
value;
|
||||
|
||||
if (blob == NULL)
|
||||
return ((unsigned long) ~0);
|
||||
|
||||
value=mutils_read_blob(blob,4,(unsigned char *) buffer);
|
||||
if (value == 0)
|
||||
return ((unsigned long) ~0);
|
||||
|
||||
value=buffer[3] << 24;
|
||||
value|=buffer[2] << 16;
|
||||
value|=buffer[1] << 8;
|
||||
value|=buffer[0];
|
||||
return(value);
|
||||
}
|
||||
|
||||
/*
|
||||
** reads a short value as a 16 bit quantity in least-significant byte first
|
||||
* order.
|
||||
*/
|
||||
unsigned short mutils_read_blob_lsb_short(MutilsBlob *blob)
|
||||
{
|
||||
unsigned char
|
||||
buffer[2];
|
||||
|
||||
unsigned short
|
||||
value;
|
||||
|
||||
if (blob == (MutilsBlob *) NULL)
|
||||
return((unsigned short) ~0);
|
||||
|
||||
value=mutils_read_blob(blob,2,(unsigned char *) buffer);
|
||||
if (value == 0)
|
||||
return((unsigned short) ~0);
|
||||
|
||||
value=buffer[1] << 8;
|
||||
value|=buffer[0];
|
||||
|
||||
return(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief reads a long value as a 32 bit quantity in most-significant byte
|
||||
* firstorder.
|
||||
* @param blob The blob
|
||||
* @param err_no If no error err_no is set to 0 other wise it is set to
|
||||
* -1
|
||||
* @param The read value as unsigned long
|
||||
*
|
||||
* The caller should always check the err_no instead of the return code,
|
||||
* because there's no other way to return a number in case of error
|
||||
*/
|
||||
unsigned long mutils_read_blob_msb_long(MutilsBlob *blob,int *err_no)
|
||||
{
|
||||
unsigned char
|
||||
buffer[4];
|
||||
|
||||
unsigned long
|
||||
value;
|
||||
|
||||
*err_no=0;
|
||||
|
||||
if (blob == (MutilsBlob *) NULL)
|
||||
{
|
||||
mutils_error("%s (%d) - mutils_read_blob_msb_long() empty blob\n",
|
||||
MUTILS_CFL);
|
||||
*err_no=(-1);
|
||||
return((unsigned long) ~0);
|
||||
}
|
||||
|
||||
value=mutils_read_blob(blob,4,(unsigned char *) buffer);
|
||||
if (value == 0)
|
||||
{
|
||||
mutils_error("%s (%d) - mutils_read_blob_msb_long() could not read 4 bytes from blob\n",MUTILS_CFL);
|
||||
*err_no=(-1);
|
||||
return((unsigned long) ~0);
|
||||
}
|
||||
/*
|
||||
** We can not return ~0 on error because if the value ffffff is read,
|
||||
** the return code will indicate it's an error
|
||||
*/
|
||||
/* return((unsigned long) ~0);*/
|
||||
|
||||
value=(unsigned long) buffer[0] << 24;
|
||||
value|=buffer[1] << 16;
|
||||
value|=buffer[2] << 8;
|
||||
value|=buffer[3];
|
||||
|
||||
return(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief reads a short value as a 16 bit quantity in most-significant byte
|
||||
* firstorder.
|
||||
* @param blob The blob
|
||||
* @param err_no If no error err_no is set to 0 other wise it is set to
|
||||
* -1
|
||||
* @return The read value as unsigned short
|
||||
*
|
||||
* The caller should always check the err_no instead of the return code,
|
||||
* because there's no other way to return a number in case of error
|
||||
*/
|
||||
unsigned short mutils_read_blob_msb_short(MutilsBlob *blob,int *err_no)
|
||||
{
|
||||
unsigned char
|
||||
buffer[2];
|
||||
|
||||
unsigned short
|
||||
value;
|
||||
|
||||
*err_no=0;
|
||||
if (blob == NULL)
|
||||
{
|
||||
mutils_error("%s (%d) - mutils_read_blob_msb_short() empty blob\n",
|
||||
MUTILS_CFL);
|
||||
*err_no=(-1);
|
||||
return((unsigned short) ~0);
|
||||
}
|
||||
|
||||
value=mutils_read_blob(blob,2,(unsigned char *) buffer);
|
||||
if (value == 0)
|
||||
{
|
||||
mutils_error("%s (%d) - mutils_read_blob_msb_short() could not read 2 bytes from blob\n",MUTILS_CFL);
|
||||
*err_no=(-1);
|
||||
return((unsigned short) ~0);
|
||||
}
|
||||
|
||||
/*
|
||||
** We can not return ~0 on error because if the value ffff is read,
|
||||
** the return code will indicate it's an error
|
||||
*/
|
||||
/* return((unsigned short) ~0);*/
|
||||
|
||||
value=(unsigned short) (buffer[0] << 8);
|
||||
value |= buffer[1];
|
||||
|
||||
return(value);
|
||||
}
|
||||
|
||||
/* reads characters from a blob until a new line or cr is read*/
|
||||
/* the string is null terminated */
|
||||
char *mutils_read_blob_string(MutilsBlob *blob,char *string,int slen)
|
||||
{
|
||||
int
|
||||
c,
|
||||
i;
|
||||
|
||||
if (blob == NULL)
|
||||
return(NULL);
|
||||
|
||||
for (i=0; i < slen; i++)
|
||||
{
|
||||
c=mutils_read_blob_byte(blob);
|
||||
if (c == -1)
|
||||
return((char *) NULL);
|
||||
string[i]=c;
|
||||
if ((string[i] == '\n') || (string[i] == '\r'))
|
||||
break;
|
||||
}
|
||||
string[i]='\0';
|
||||
return(string);
|
||||
}
|
||||
|
||||
/* returns current size of the blob */
|
||||
/* -1 on error */
|
||||
int mutils_size_blob(MutilsBlob *blob)
|
||||
{
|
||||
if (blob == NULL)
|
||||
return(-1);
|
||||
|
||||
if (blob->data != (unsigned char *) NULL)
|
||||
return(blob->length);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* returns the current value of the blob position */
|
||||
/* -1 on failure */
|
||||
int mutils_tell_blob(MutilsBlob *blob)
|
||||
{
|
||||
if (blob == NULL)
|
||||
return(-1);
|
||||
|
||||
if (blob->data != (unsigned char *) NULL)
|
||||
return(blob->offset);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes length bytes of data to blob
|
||||
* @param blob The blob to fill with data
|
||||
* @param length Length of data
|
||||
* @param data Data to write to blob
|
||||
*
|
||||
* blob->data must have at least blob->length bytes of data pre-allocated.
|
||||
* If we need more than that, memory will be allocated dynamically.
|
||||
*
|
||||
* blob->offset is incremented with the amount of data written to blob
|
||||
*
|
||||
* This code is adapted from ImageMagick. ImageMagick's version reallocate
|
||||
* data bultiple of 8 bytes. This one allocates exact number of bytes as
|
||||
* needed.
|
||||
*
|
||||
*/
|
||||
int mutils_write_blob(MutilsBlob *blob,const size_t length,const void *data)
|
||||
{
|
||||
int
|
||||
reallocate_bytes=0;
|
||||
|
||||
if (blob == (MutilsBlob *) NULL)
|
||||
return(-1);
|
||||
|
||||
if (blob->data != (unsigned char *) NULL)
|
||||
{
|
||||
if (length > (blob->length - blob->offset))
|
||||
{
|
||||
reallocate_bytes=(length - (blob->length - blob->offset));
|
||||
mutils_info("%s (%d) out of memory, re-allocating %d bytes\n",
|
||||
MUTILS_CFL,reallocate_bytes);
|
||||
/* find out how many bytes we need to re-allocate */
|
||||
blob->length += reallocate_bytes;
|
||||
mutils_reacquire_memory((void **) &blob->data,blob->length);
|
||||
if (blob->data == (unsigned char *) NULL)
|
||||
{
|
||||
mutils_detach_blob(blob);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
(void) memcpy(blob->data + blob->offset,data,length);
|
||||
blob->offset += length;
|
||||
if (blob->offset > (off_t) blob->length)
|
||||
blob->length=blob->offset;
|
||||
return(length);
|
||||
}
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
** write an integer to a blob. It returns the number of bytes written
|
||||
** and -1 on failure
|
||||
*/
|
||||
size_t mutils_write_blob_byte(MutilsBlob *blob,const long value)
|
||||
{
|
||||
|
||||
unsigned char
|
||||
buffer[1];
|
||||
|
||||
if (blob == NULL)
|
||||
return(-1);
|
||||
|
||||
buffer[0]=(unsigned char) value;
|
||||
return(mutils_write_blob(blob,1,buffer));
|
||||
}
|
||||
/*
|
||||
** writes a long value as a 32 bit quantity in least-significant byte first
|
||||
** order. returns the number of unsigned longs written. -1 on error
|
||||
*/
|
||||
int mutils_write_blob_lsb_long(MutilsBlob *blob,const unsigned long value)
|
||||
{
|
||||
unsigned char
|
||||
buffer[4];
|
||||
|
||||
if (blob == NULL)
|
||||
return(-1);
|
||||
|
||||
buffer[0]=(unsigned char) value;
|
||||
buffer[1]=(unsigned char) (value >> 8);
|
||||
buffer[2]=(unsigned char) (value >> 16);
|
||||
buffer[3]=(unsigned char) (value >> 24);
|
||||
|
||||
return(mutils_write_blob(blob,4,buffer));
|
||||
}
|
||||
|
||||
/*
|
||||
** writes a long value as a 16 bit quantity in least-significant byte first
|
||||
** order. returns the number of unsigned longs written. -1 on failure
|
||||
*/
|
||||
int mutils_write_blob_lsb_short(MutilsBlob *blob,const unsigned long value)
|
||||
{
|
||||
unsigned char
|
||||
buffer[2];
|
||||
|
||||
if (blob == NULL)
|
||||
return(-1);
|
||||
|
||||
buffer[0]=(unsigned char) value;
|
||||
buffer[1]=(unsigned char) (value >> 8);
|
||||
|
||||
return(mutils_write_blob(blob,2,buffer));
|
||||
}
|
||||
|
||||
/*
|
||||
** writes a long value as a 32 bit quantity in most-significant byte first
|
||||
** order. returns the number of unsigned longs written. -1 on failure
|
||||
*/
|
||||
int mutils_write_blob_msb_long(MutilsBlob *blob,const unsigned long value)
|
||||
{
|
||||
unsigned char
|
||||
buffer[4];
|
||||
|
||||
if (blob == NULL)
|
||||
return(-1);
|
||||
|
||||
buffer[0]=(unsigned char) (value >> 24);
|
||||
buffer[1]=(unsigned char) (value >> 16);
|
||||
buffer[2]=(unsigned char) (value >> 8);
|
||||
buffer[3]=(unsigned char) value;
|
||||
|
||||
return(mutils_write_blob(blob,4,buffer));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
** writes a long value as a 16 bit quantity in most-significant byte first
|
||||
** order. returns the number of unsigned longs written. -1 on failure
|
||||
*/
|
||||
int mutils_write_blob_msb_short(MutilsBlob *blob,const unsigned long value)
|
||||
{
|
||||
unsigned char
|
||||
buffer[2];
|
||||
|
||||
if (blob == NULL)
|
||||
return(-1);
|
||||
|
||||
buffer[0]=(unsigned char) (value >> 8);
|
||||
buffer[1]=(unsigned char) value;
|
||||
|
||||
return(mutils_write_blob(blob,2,buffer));
|
||||
}
|
||||
|
||||
/*
|
||||
** write a string to a blob. It returns the number of characters written
|
||||
*/
|
||||
size_t mutils_write_blob_string(MutilsBlob *blob,const char *string)
|
||||
{
|
||||
if (string == NULL)
|
||||
return(0);
|
||||
|
||||
if (blob == NULL)
|
||||
return(0);
|
||||
|
||||
return(mutils_write_blob(blob,strlen(string),string));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mutils_hex_dump_blob(FILE *fp,MutilsBlob *blob)
|
||||
{
|
||||
if (blob && blob->data)
|
||||
{
|
||||
if (blob->length)
|
||||
mutils_hex_dump(fp,blob->data,blob->length);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void) fprintf(stderr,"Empty blob\n");
|
||||
}
|
||||
}
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
#include "mutils.h"
|
||||
/*
|
||||
** Allow the caller to register a error printing routine
|
||||
*/
|
||||
|
||||
static int s_mutils_debug=0;
|
||||
|
||||
|
||||
static void mutils_default_proc(char *fmt,va_list args)
|
||||
{
|
||||
if (fmt)
|
||||
{
|
||||
vfprintf(stderr,fmt,args);
|
||||
(void) fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
||||
static void mutils_default_hexdump_proc(unsigned char *bytes,int bytes_len)
|
||||
{
|
||||
if (bytes && bytes_len > 0)
|
||||
{
|
||||
mutils_hex_dump(stderr,bytes,bytes_len);
|
||||
}
|
||||
}
|
||||
|
||||
static void mutils_default_hexprint_proc(unsigned char *bytes,
|
||||
int bytes_len)
|
||||
{
|
||||
if (bytes && bytes_len > 0)
|
||||
{
|
||||
mutils_hex_print(stderr,bytes,bytes_len);
|
||||
}
|
||||
}
|
||||
|
||||
/* default error, info and warning printing routine */
|
||||
static mutils_error_func mutils_error_hook=mutils_default_proc;
|
||||
static mutils_error_func mutils_info_hook=mutils_default_proc;
|
||||
static mutils_error_func mutils_debug_hook=mutils_default_proc;
|
||||
static mutils_error_func mutils_warn_hook=mutils_default_proc;
|
||||
static mutils_hexdump_func mutils_hexdump_hook=mutils_default_hexdump_proc;
|
||||
static mutils_hexdump_func mutils_hexprint_hook=mutils_default_hexprint_proc;
|
||||
|
||||
static void mutils_error_va(char *fmt,va_list args)
|
||||
{
|
||||
(*mutils_error_hook)(fmt,args);
|
||||
}
|
||||
|
||||
static void mutils_info_va(char *fmt,va_list args)
|
||||
{
|
||||
(*mutils_info_hook)(fmt,args);
|
||||
}
|
||||
|
||||
static void mutils_debug_va(char *fmt,va_list args)
|
||||
{
|
||||
(*mutils_debug_hook)(fmt,args);
|
||||
}
|
||||
|
||||
static void mutils_warn_va(char *fmt,va_list args)
|
||||
{
|
||||
(*mutils_warn_hook)(fmt,args);
|
||||
}
|
||||
|
||||
|
||||
void mutils_hexdump(unsigned char *bytes,int bytes_len)
|
||||
{
|
||||
(*mutils_hexdump_hook)(bytes,bytes_len);
|
||||
}
|
||||
|
||||
void mutils_hexprint(unsigned char *bytes,int bytes_len)
|
||||
{
|
||||
(*mutils_hexprint_hook)(bytes,bytes_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turn debug on or off
|
||||
* @param d If 1, turn debug 1, if 0 turn debug off
|
||||
*/
|
||||
void mutils_set_debug(int d)
|
||||
{
|
||||
if (d == 1)
|
||||
{
|
||||
s_mutils_debug=1;
|
||||
}
|
||||
else if (d == 0)
|
||||
{
|
||||
s_mutils_debug=0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set application defined function for printing error messages
|
||||
*/
|
||||
void mutils_set_error_hook(mutils_error_func new_func)
|
||||
{
|
||||
if (new_func)
|
||||
{
|
||||
mutils_error_hook=new_func;
|
||||
}
|
||||
else
|
||||
{
|
||||
mutils_error_hook=mutils_default_proc;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set application defined function for printing info messages
|
||||
*/
|
||||
void mutils_set_info_hook(mutils_error_func new_func)
|
||||
{
|
||||
if (new_func)
|
||||
{
|
||||
mutils_info_hook=new_func;
|
||||
}
|
||||
else
|
||||
{
|
||||
mutils_info_hook=mutils_default_proc;
|
||||
}
|
||||
}
|
||||
|
||||
void mutils_set_debug_hook(mutils_error_func new_func)
|
||||
{
|
||||
if (new_func)
|
||||
{
|
||||
mutils_debug_hook=new_func;
|
||||
}
|
||||
else
|
||||
{
|
||||
mutils_debug_hook=mutils_default_proc;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Set application defined function for printing warning messages
|
||||
*/
|
||||
void mutils_set_warn_hook(mutils_error_func new_func)
|
||||
{
|
||||
if (new_func)
|
||||
{
|
||||
mutils_warn_hook=new_func;
|
||||
}
|
||||
else
|
||||
{
|
||||
mutils_warn_hook=mutils_default_proc;
|
||||
}
|
||||
}
|
||||
|
||||
void mutils_set_hexdump_hook(mutils_hexdump_func new_func)
|
||||
{
|
||||
if (new_func)
|
||||
{
|
||||
mutils_hexdump_hook=new_func;
|
||||
}
|
||||
else
|
||||
{
|
||||
mutils_hexdump_hook=mutils_default_hexdump_proc;
|
||||
}
|
||||
}
|
||||
|
||||
void mutils_set_hexprint_hook(mutils_hexdump_func new_func)
|
||||
{
|
||||
if (new_func)
|
||||
{
|
||||
mutils_hexprint_hook=new_func;
|
||||
}
|
||||
else
|
||||
{
|
||||
mutils_hexprint_hook=mutils_default_hexprint_proc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mutils_reset_error_hook(void)
|
||||
{
|
||||
mutils_set_error_hook(NULL);
|
||||
}
|
||||
|
||||
void mutils_reset_info_hook(void)
|
||||
{
|
||||
mutils_set_info_hook(NULL);
|
||||
}
|
||||
|
||||
void mutils_reset_warn_hook(void)
|
||||
{
|
||||
mutils_set_warn_hook(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief print error message
|
||||
@param fmt The formatted parameters
|
||||
|
||||
This function prints eror message to standard error if no application
|
||||
error printing is not hooked by calling mutils_set_error_hook()
|
||||
*/
|
||||
void mutils_error(char *fmt,...)
|
||||
{
|
||||
va_list
|
||||
ap;
|
||||
|
||||
va_start(ap,fmt);
|
||||
mutils_error_va(fmt,ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void mutils_info(char *fmt,...)
|
||||
{
|
||||
va_list
|
||||
ap;
|
||||
|
||||
va_start(ap,fmt);
|
||||
mutils_info_va(fmt,ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void mutils_warn(char *fmt,...)
|
||||
{
|
||||
va_list
|
||||
ap;
|
||||
|
||||
va_start(ap,fmt);
|
||||
mutils_warn_va(fmt,ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void mutils_debug(char *fmt,...)
|
||||
{
|
||||
va_list
|
||||
ap;
|
||||
|
||||
va_start(ap,fmt);
|
||||
mutils_debug_va(fmt,ap);
|
||||
va_end(ap);
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
#include "mutils.h"
|
||||
|
||||
static char base64_chars[64] =
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
|
||||
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
|
||||
't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', '+', '/'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** generateBoundary()
|
||||
** generate unuque string for boundary for MIME tag
|
||||
**
|
||||
** Parameters:
|
||||
** char *boundary - NULL terminated boundary string - returns
|
||||
** int len - size of boundary (malloc'd or static)
|
||||
**
|
||||
** Return Values:
|
||||
** none
|
||||
**
|
||||
** Limitations and Comments:
|
||||
** boundary must have len bytes in it to store the boundary. the
|
||||
functio
|
||||
n
|
||||
** calls rand() for random number, so the caller should call srand()
|
||||
** before calling this function.
|
||||
**
|
||||
** This function is adapted from mutt code.
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** muquit@muquit.com Mar-06-2002 needs MIME support
|
||||
*/
|
||||
#define BOUNDARY_LEN 16
|
||||
void mutilsGenerateMIMEBoundary(char *boundary,int len)
|
||||
{
|
||||
char
|
||||
*p;
|
||||
int
|
||||
i;
|
||||
memset(boundary,0,len);
|
||||
p=boundary;
|
||||
for (i=0; i < BOUNDARY_LEN; i++)
|
||||
{
|
||||
if (i >= (len-1))
|
||||
break;
|
||||
*p++ = base64_chars[rand() % sizeof(base64_chars)];
|
||||
}
|
||||
*p='\0';
|
||||
}
|
||||
|
||||
static void output64Chunk(int c1,int c2,int c3,int pads, FILE *outfile)
|
||||
{
|
||||
putc(base64_chars[c1>>2], outfile);
|
||||
putc(base64_chars[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)], outfile);
|
||||
if (pads == 2)
|
||||
{
|
||||
putc('=', outfile);
|
||||
putc('=', outfile);
|
||||
}
|
||||
else if (pads)
|
||||
{
|
||||
putc(base64_chars[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)], outfile);
|
||||
putc('=', outfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
putc(base64_chars[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)], outfile);
|
||||
putc(base64_chars[c3 & 0x3F], outfile);
|
||||
}
|
||||
}
|
||||
|
||||
void mutilsBase64Encode(FILE *ifp,FILE *ofp)
|
||||
{
|
||||
int
|
||||
c1,
|
||||
c2,
|
||||
c3,
|
||||
ct=0;
|
||||
|
||||
while ((c1=getc(ifp)) != EOF)
|
||||
{
|
||||
c2=getc(ifp);
|
||||
if (c2 == EOF)
|
||||
{
|
||||
output64Chunk(c1,0,0,2,ofp);
|
||||
}
|
||||
else
|
||||
{
|
||||
c3=getc(ifp);
|
||||
if (c3 == EOF)
|
||||
{
|
||||
output64Chunk(c1,c2,0,1,ofp);
|
||||
}
|
||||
else
|
||||
{
|
||||
output64Chunk(c1,c2,c3,0,ofp);
|
||||
}
|
||||
}
|
||||
ct += 4;
|
||||
if (ct > 71)
|
||||
{
|
||||
putc('\r',ofp); /* qmail fix 15.07.05 (movi) */
|
||||
putc('\n',ofp);
|
||||
ct=0;
|
||||
}
|
||||
}
|
||||
if (ct)
|
||||
{
|
||||
putc('\r',ofp); /* qmail fix 15.07.05 (movi) */
|
||||
putc('\n',ofp);
|
||||
}
|
||||
|
||||
(void) fflush(ofp);
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
#include "mutils.h"
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
** return the path of current working directory
|
||||
*/
|
||||
char *mutils_getcwd(char *buf,int buflen)
|
||||
{
|
||||
if (getcwd(buf,buflen - 1) != NULL)
|
||||
{
|
||||
return(buf);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
** tmpdir - path of temp directory
|
||||
** tempfile_path - returns. path of temp filename
|
||||
** buflen - length of tempfile_path buffer, preallocated
|
||||
**
|
||||
** returns: open FILE pointer to temp file
|
||||
*/
|
||||
static FILE *open_tempfile(const char *tempdir,char *tempfile_path,int buflen)
|
||||
{
|
||||
FILE
|
||||
*fp = NULL;
|
||||
|
||||
int
|
||||
rc,
|
||||
tfwd,
|
||||
len = strlen(tempdir);
|
||||
|
||||
if (len && len < MUTILS_PATH_MAX)
|
||||
{
|
||||
(void) snprintf(tempfile_path,buflen - 1,"%s/%s",tempdir,"mailsendXXXXXX");
|
||||
#ifdef HAVE_MKSTEMP
|
||||
tfwd = mkstemp(tempfile_path);
|
||||
if (tfwd == -1)
|
||||
{
|
||||
mutils_error("%s (%d) - Could not open tmp file %s for writing: %s\n",
|
||||
MUTILS_CFL,
|
||||
tempfile_path,
|
||||
strerror(errno));
|
||||
return(0);
|
||||
}
|
||||
|
||||
fp = fdopen(tfwd,"w");
|
||||
if (fp == NULL)
|
||||
{
|
||||
mutils_error("%s (%d) - Could not open temp file %s\n",
|
||||
MUTILS_CFL,
|
||||
tempfile_path);
|
||||
return(NULL);
|
||||
}
|
||||
return(fp);
|
||||
#else
|
||||
#ifdef WINNT
|
||||
rc = _mktemp_s(tempfile_path, buflen);
|
||||
if (rc != 0)
|
||||
{
|
||||
mutils_error("%s (%d) - Could not create file %s\n",
|
||||
MUTILS_CFL,
|
||||
tempfile_path);
|
||||
return(NULL);
|
||||
}
|
||||
fp = fopen(tempfile_path,"w");
|
||||
if (fp == NULL)
|
||||
{
|
||||
mutils_error("%s (%d) - Could not open temp file %s\n",
|
||||
MUTILS_CFL,
|
||||
tempfile_path);
|
||||
return(NULL);
|
||||
}
|
||||
#else
|
||||
mktemp(tempfile_path);
|
||||
fp = fopen(tempfile_path,"w");
|
||||
if (fp == NULL)
|
||||
{
|
||||
mutils_error("%s (%d) - Could not open temp file %s\n",
|
||||
MUTILS_CFL,
|
||||
tempfile_path);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#endif /* WINNT */
|
||||
#endif /* HAVE_MKSTEMP */
|
||||
}
|
||||
|
||||
return(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return FILE pointer to a open temp file.
|
||||
** Parameters:
|
||||
** tempfile_path - returns. The buffer to hold the temp file path
|
||||
** buflen - Length of tempfile_path
|
||||
** Returns:
|
||||
** FILE pointer to tempfile on success, NULL on failure
|
||||
**
|
||||
** The caller is responsible to close the FILE pointer and remove the file
|
||||
**
|
||||
** Note: adapted from apache apr lib
|
||||
*/
|
||||
FILE *mutils_get_tempfileFP(char *tempfile_path,int buflen)
|
||||
{
|
||||
char
|
||||
tmpbuf[MUTILS_PATH_MAX];
|
||||
|
||||
int
|
||||
tfwd;
|
||||
|
||||
FILE
|
||||
*fp = NULL;
|
||||
|
||||
char
|
||||
*dir = NULL;
|
||||
|
||||
const char *try_envs[] =
|
||||
{
|
||||
"TMP",
|
||||
"TEMP",
|
||||
"TMPDIR",
|
||||
};
|
||||
|
||||
const char *try_dirs[] =
|
||||
{
|
||||
"/tmp",
|
||||
"/usr/tmp",
|
||||
"/var/tmp",
|
||||
};
|
||||
|
||||
char
|
||||
*tempdir;
|
||||
|
||||
int
|
||||
i;
|
||||
|
||||
/* first look for the env vars */
|
||||
for (i = 0; i < (sizeof(try_envs) / sizeof(const char *)); i++)
|
||||
{
|
||||
|
||||
tempdir = getenv(try_envs[i]);
|
||||
if (tempdir != NULL)
|
||||
{
|
||||
int
|
||||
len = strlen(tempdir);
|
||||
fp = open_tempfile(tempdir,tempfile_path,buflen);
|
||||
if (fp != NULL)
|
||||
goto ExitProcessing;
|
||||
}
|
||||
}
|
||||
|
||||
/* we could not find the env vars for temp dir */
|
||||
/* try c:/TMP for windows */
|
||||
#ifdef WINNT
|
||||
fp = open_tempfile("c:/TEMP",tempfile_path, buflen);
|
||||
if (fp != NULL)
|
||||
goto ExitProcessing;
|
||||
#endif /* WINNT */
|
||||
|
||||
/* Next try some hard coded path */
|
||||
for (i = 0; i < (sizeof(try_dirs) / sizeof(const char *)); i++)
|
||||
{
|
||||
fp = open_tempfile(try_dirs[i], tempfile_path, buflen);
|
||||
if (fp != NULL)
|
||||
goto ExitProcessing;
|
||||
}
|
||||
|
||||
/* Finally, try the current working directory */
|
||||
tempdir = mutils_getcwd(tmpbuf,sizeof(tmpbuf)-1);
|
||||
if (tempdir != NULL)
|
||||
{
|
||||
fp = open_tempfile(tempdir, tempfile_path, buflen);
|
||||
if (fp != NULL)
|
||||
goto ExitProcessing;
|
||||
}
|
||||
|
||||
ExitProcessing:
|
||||
return(fp);
|
||||
}
|
||||
|
||||
#ifdef TESTING
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
char
|
||||
*pwd,
|
||||
tempfile[MUTILS_PATH_MAX];
|
||||
|
||||
FILE
|
||||
*fp;
|
||||
|
||||
fp = mutils_get_tempfileFP(tempfile, MUTILS_PATH_MAX);
|
||||
if (fp)
|
||||
{
|
||||
(void) fprintf(stderr,"%s\n",tempfile);
|
||||
(void) fclose(fp);
|
||||
unlink(tempfile);
|
||||
}
|
||||
pwd = mutils_getcwd(tempfile,sizeof(tempfile));
|
||||
if (pwd)
|
||||
(void) fprintf(stderr,"pwd=%s\n",pwd);
|
||||
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
@file mutils_time.c
|
||||
@author Muhamad A Muquit
|
||||
@date $Date:$
|
||||
@version $Revision:$
|
||||
@brief Platform independ wrapper routines for time
|
||||
*/
|
||||
|
||||
#include "mutils.h"
|
||||
|
||||
/* returns 0 on success, -1 on failure */
|
||||
int mutils_time_now(MutilsTime *mt)
|
||||
{
|
||||
int
|
||||
rc=(-1);
|
||||
|
||||
#ifdef WINNT
|
||||
#else
|
||||
struct timeval
|
||||
tv;
|
||||
#endif /* WINNT */
|
||||
|
||||
#ifdef WINNT
|
||||
GetSystemTimeAsFileTime(&mt->absolute);
|
||||
#else
|
||||
rc=gettimeofday(&tv,NULL);
|
||||
if (rc == -1)
|
||||
{
|
||||
mutils_error("gettimeofday() failed");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
mt->secs=tv.tv_sec;
|
||||
mt->nsecs=tv.tv_usec * 1000;
|
||||
#endif /* WINNT */
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* buf must be at least 64 bytes allocated and bufsiz must reflect that */
|
||||
/* adapted from ISC time.c */
|
||||
void mutils_time_fmt(MutilsTime *mt,char *buf,int bufsiz)
|
||||
{
|
||||
time_t
|
||||
now;
|
||||
|
||||
int
|
||||
rc;
|
||||
#ifdef WINNT
|
||||
FILETIME
|
||||
localft;
|
||||
SYSTEMTIME
|
||||
st;
|
||||
char
|
||||
DateBuf[50],
|
||||
TimeBuf[50];
|
||||
|
||||
static const char
|
||||
badtime[] = "99-Bad-9999 99:99:99.999";
|
||||
#endif /* WINNT */
|
||||
|
||||
if (bufsiz < 64)
|
||||
return;
|
||||
#ifdef WINNT
|
||||
if (FileTimeToLocalFileTime(&mt->absolute, &localft) &&
|
||||
FileTimeToSystemTime(&localft, &st))
|
||||
{
|
||||
GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, "dd-MMM-yyyy",
|
||||
DateBuf, 50);
|
||||
GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER|
|
||||
TIME_FORCE24HOURFORMAT, &st, NULL, TimeBuf, 50);
|
||||
|
||||
snprintf(buf, bufsiz, "%s %s.%03u", DateBuf, TimeBuf,
|
||||
st.wMilliseconds);
|
||||
}
|
||||
else
|
||||
snprintf(buf, bufsiz, badtime);
|
||||
#else
|
||||
now=(time_t) mt->secs;
|
||||
rc=strftime(buf,bufsiz,"%d-%b-%Y %X",localtime(&now));
|
||||
if (rc != 0)
|
||||
(void) snprintf(buf+rc,bufsiz - rc,".%03u",mt->nsecs / 1000000);
|
||||
else
|
||||
(void) snprintf(buf+rc,bufsiz - 1,"99-Bad-9999 99:99:99.999"); /* from isc */
|
||||
#endif /* WINNT */
|
||||
}
|
||||
|
||||
#ifdef TEST_TIME
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
char
|
||||
buf[65];
|
||||
|
||||
MutilsTime
|
||||
mt;
|
||||
|
||||
mutils_time_now(&mt);
|
||||
mutils_time_fmt(&mt,MUTILS_TRUE,buf,sizeof(buf));
|
||||
(void) fprintf(stderr,"%s\n",buf);
|
||||
}
|
||||
#endif /* TEST_TIME */
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#
|
||||
# for Singly linked list package.
|
||||
# muhammad a muquit
|
||||
# Aug-07-1998
|
||||
#
|
||||
CC= @CC@
|
||||
DEFS= @DEFS@
|
||||
AR= ar cq
|
||||
RANLIB= @RANLIB@
|
||||
LIBNAME= libsll.a
|
||||
|
||||
INCLUDES= -I.
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DSYS_UNIX=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
|
||||
SRCS = sll.c
|
||||
OBJS = sll.o
|
||||
|
||||
.c.o:
|
||||
rm -f $@
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
all: $(LIBNAME)
|
||||
|
||||
$(LIBNAME): $(OBJS)
|
||||
rm -f $@
|
||||
$(AR) $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
sll.o: sll.h
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(LIBNAME) core a.out
|
||||
|
||||
realclean:
|
||||
rm -f $(OBJS) $(LIBNAME) core a.out config.cache config.log config.status
|
||||
(cd examples/append;make clean)
|
||||
(cd examples/append_sorted;make clean)
|
||||
(cd examples/delete;make clean)
|
||||
(cd examples/insert;make clean)
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#--------------------------------------------
|
||||
# Makefile for MS Visual C++
|
||||
# muquit@muquit.com
|
||||
#--------------------------------------------
|
||||
|
||||
DEFS= -DWINNT=1 -DSTRICT_MODE=1 -DHAVE_STRING_H=1 -DHAVE_FCNTL_H=1
|
||||
CFLAGS= /DWINNT /DWIN32 /DHAVE_MALLOC_H /I.
|
||||
CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo
|
||||
LIBFLAGS=/nologo
|
||||
LIBRARY=sll.lib
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS)
|
||||
#CFLAGS= $(cvars) $(cdebug) -nologo -G4 $(DEFINES)
|
||||
|
||||
|
||||
SRCS = sll.c
|
||||
OBJS = sll.obj
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
lib $(LIBFLAGS) $(OBJS) /out:$(LIBRARY)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(LIBRARY) *.bak
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
A Singly Linked List library. You'll need a ANSI C compiler in order to
|
||||
compile.
|
||||
|
||||
Please visit the URL: http://www.fccc.edu/users/muquit/libsll/libsll.html
|
||||
for reference.
|
||||
|
||||
--
|
||||
Muhammad A Muquit
|
||||
Aug-09-1998.
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
#The current version of ssl lib is 1.1
|
||||
SLL_VERSION=sll
|
||||
+1722
File diff suppressed because it is too large
Load Diff
+40
@@ -0,0 +1,40 @@
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(sll.h)
|
||||
|
||||
dnl AC_CONFIG_HEADER(config.h)
|
||||
|
||||
dnl Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_RANLIB
|
||||
AC_PROG_MAKE_SET
|
||||
|
||||
dnl Checks for libraries.
|
||||
|
||||
dnl Checks for header files.
|
||||
dnl AC_HEADER_STDC
|
||||
AC_STDC_HEADERS
|
||||
AC_HEADER_SYS_WAIT
|
||||
AC_HEADER_TIME
|
||||
AC_CHECK_HEADERS(string.h fcntl.h memory.h malloc.h unistd.h ctype.h)
|
||||
AC_CHECK_HEADERS(strings.h)
|
||||
|
||||
AC_CHECK_HEADERS(sys/stat.h sys/param.h sys/file.h stdlib.h)
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
AC_STRUCT_TM
|
||||
AC_CHECK_FUNC(flock,AC_DEFINE(HAVE_FLOCK))
|
||||
AC_CHECK_FUNC(strcasecmp,AC_DEFINE(HAVE_STRCASECMP))
|
||||
AC_CHECK_FUNC(mktime,AC_DEFINE(HAVE_MKTIME))
|
||||
AC_CHECK_FUNC(ftruncate,AC_DEFINE(HAVE_FTRUNCATE))
|
||||
dnl from vile configure.in, I love vile, a great editor
|
||||
AC_MSG_CHECKING([for SCO])
|
||||
AC_PROGRAM_CHECK(COULD_BE_SCO, [scosh], maybe, maybenot)
|
||||
if test "$COULD_BE_SCO" = "maybe"
|
||||
then
|
||||
AC_DEFINE(SYSTEM_LOOKS_LIKE_SCO)
|
||||
fi
|
||||
|
||||
dnl Checks for library functions.
|
||||
|
||||
AC_OUTPUT(Makefile examples/insert/Makefile examples/append/Makefile\
|
||||
examples/delete/Makefile examples/append_sorted/Makefile)
|
||||
@@ -0,0 +1,31 @@
|
||||
##
|
||||
# Makefile automatically generated by genmake 1.0, Nov-12-98
|
||||
# genmake 1.0 by ma_muquit@fccc.edu, RCS
|
||||
##
|
||||
CC= @CC@
|
||||
DEFS= @DEFS@
|
||||
PROGNAME= sll_append
|
||||
INCLUDES= -I../..
|
||||
LIBS= -L../../ -lsll
|
||||
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DSYS_UNIX=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
|
||||
SRCS = append.c
|
||||
|
||||
OBJS = append.o
|
||||
|
||||
.c.o:
|
||||
rm -f $@
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
all: $(PROGNAME)
|
||||
|
||||
$(PROGNAME) : $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(PROGNAME) core
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
** test appending a node at the end of the list. print the result
|
||||
** and then free the memory. a user defined function is called to free
|
||||
** the data.
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Aug-09-1998 first cut
|
||||
*/
|
||||
|
||||
|
||||
#include <sll.h>
|
||||
|
||||
typedef struct _addr
|
||||
{
|
||||
char
|
||||
*name,
|
||||
*city,
|
||||
*state;
|
||||
} Addr;
|
||||
|
||||
static void freeData(void **data);
|
||||
|
||||
int main (int argc,char **argv)
|
||||
{
|
||||
Sll
|
||||
*l,
|
||||
*head=NULL,
|
||||
*new=NULL;
|
||||
Addr
|
||||
*addr;
|
||||
|
||||
int
|
||||
n=0;
|
||||
|
||||
(void) fprintf(stderr,
|
||||
"=========================================================================\n");
|
||||
(void) fprintf(stderr," Testing Append a node at the beginning of a list\n");
|
||||
(void) fprintf(stderr,
|
||||
"=========================================================================\n");
|
||||
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
(void) fprintf(stderr,"\n---------------[ appending ]----------\n");
|
||||
/*
|
||||
** it will be the last node
|
||||
*/
|
||||
addr->name=strdup("Muhammad A Muquit");
|
||||
addr->city=strdup("Philadelphia");
|
||||
addr->state=strdup("PA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
new=allocateNode((void *) addr);
|
||||
appendNode(&head,&new);
|
||||
(void) fprintf(stderr,"Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
/*
|
||||
** append node after the last one
|
||||
*/
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
addr->name=strdup("Janet Hunter");
|
||||
addr->city=strdup("Santa Clara");
|
||||
addr->state=strdup("CA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
new=allocateNode((void *) addr);
|
||||
appendNode(&head,&new);
|
||||
(void) fprintf(stderr,"Appending Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
|
||||
/*
|
||||
** append node after the last one
|
||||
*/
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
addr->name=strdup("Babs Jensen");
|
||||
addr->city=strdup("Cupertino");
|
||||
addr->state=strdup("CA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
new=allocateNode((void *) addr);
|
||||
appendNode(&head,&new);
|
||||
(void) fprintf(stderr,"Appending Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
/*
|
||||
** print
|
||||
*/
|
||||
(void) fprintf(stderr,"\n---------------[ printing ]----------\n");
|
||||
n=0;
|
||||
for (l=head; l; l=l->next)
|
||||
{
|
||||
addr=(Addr *) l->data;
|
||||
(void) fprintf(stderr,"Node: %d\n",++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
}
|
||||
|
||||
/*
|
||||
** free nodes
|
||||
*/
|
||||
(void) fprintf(stderr,"\n---------------[ freeing ]----------\n");
|
||||
destroyNodes(&head,freeData);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** routine to free the user data
|
||||
*/
|
||||
|
||||
static void freeData(void **data)
|
||||
{
|
||||
Addr
|
||||
**addr=(Addr **) data;
|
||||
|
||||
static int
|
||||
n=0;
|
||||
|
||||
n++;
|
||||
if (*addr)
|
||||
{
|
||||
if ((*addr)->name)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->name);
|
||||
(void) free((char *) (*addr)->name);
|
||||
}
|
||||
if ((*addr)->city)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->city);
|
||||
(void) free ((char *) (*addr)->city);
|
||||
}
|
||||
if ((*addr)->state)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->state);
|
||||
(void) free ((char *) (*addr)->state);
|
||||
}
|
||||
|
||||
(void) fprintf(stderr,"Freeing the node %d itself\n\n",n);
|
||||
(void) free((char *) (*addr));
|
||||
(*addr)=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
##
|
||||
# Makefile automatically generated by genmake 1.0, Mar-27-2001
|
||||
# genmake 1.0 by muquit@muquit.com http://www.muquit.com/
|
||||
##
|
||||
CC= cl
|
||||
DEFS= -nologo -G3
|
||||
PROGNAME= append
|
||||
LINKER=link -nologo
|
||||
INCLUDES= -I. -I../../
|
||||
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DWINNT=1 -DSYS_WIN32=1 -DHAVE_STRING_H=1 -DHAVE_FCNTL_H=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
SLL_LIB=../../sll.lib
|
||||
LIBS=$(SLL_LIB) user32.lib gdi32.lib winmm.lib comdlg32.lib comctl32.lib
|
||||
RC=rc
|
||||
RCVARS=-r -DWIN32
|
||||
|
||||
SRCS = append.c
|
||||
|
||||
OBJS = append.obj
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c $< -Fo$@
|
||||
|
||||
all: $(PROGNAME)
|
||||
|
||||
$(PROGNAME) : $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(PROGNAME)
|
||||
@@ -0,0 +1,31 @@
|
||||
##
|
||||
# Makefile automatically generated by genmake 1.0, Nov-12-98
|
||||
# genmake 1.0 by ma_muquit@fccc.edu, RCS
|
||||
##
|
||||
CC= @CC@
|
||||
DEFS= @DEFS@
|
||||
PROGNAME= sll_append_sorted
|
||||
INCLUDES= -I../..
|
||||
LIBS= -L../../ -lsll
|
||||
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DSYS_UNIX=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
|
||||
SRCS = append_sorted.c
|
||||
|
||||
OBJS = append_sorted.o
|
||||
|
||||
.c.o:
|
||||
rm -f $@
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
all: $(PROGNAME)
|
||||
|
||||
$(PROGNAME) : $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(PROGNAME) core
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
** Appends a node to the end of a list sorted. The data of two lists are
|
||||
** passed to the user defined function compFunction for sorting.
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Aug-09-1998 first cut
|
||||
*/
|
||||
|
||||
#include <sll.h>
|
||||
|
||||
typedef struct _addr
|
||||
{
|
||||
char
|
||||
*name,
|
||||
*city,
|
||||
*state;
|
||||
} Addr;
|
||||
|
||||
static void freeData(void **data);
|
||||
static int compFunc(void *a1,void *a2);
|
||||
|
||||
int main (int argc,char **argv)
|
||||
{
|
||||
Sll
|
||||
*l,
|
||||
*head=NULL,
|
||||
*new=NULL;
|
||||
Addr
|
||||
*addr;
|
||||
|
||||
int
|
||||
n=0;
|
||||
|
||||
(void) fprintf(stderr,
|
||||
"=========================================================================\n");
|
||||
(void) fprintf(stderr," Testing Append a node at the beginning of a list\n");
|
||||
(void) fprintf(stderr,
|
||||
"=========================================================================\n");
|
||||
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
(void) fprintf(stderr,"\n---------------[ appending ]----------\n");
|
||||
/*
|
||||
** it will be the last node
|
||||
*/
|
||||
addr->name=strdup("Cindy Muquit");
|
||||
addr->city=strdup("Philadelphia");
|
||||
addr->state=strdup("PA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
new=allocateNode((void *) addr);
|
||||
appendNodeSorted(&head,&new,compFunc);
|
||||
(void) fprintf(stderr,"Appending Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
/*
|
||||
** append node before the last one
|
||||
*/
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
addr->name=strdup("Janet Hunter");
|
||||
addr->city=strdup("Santa Clara");
|
||||
addr->state=strdup("CA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
new=allocateNode((void *) addr);
|
||||
appendNodeSorted(&head,&new,compFunc);
|
||||
(void) fprintf(stderr,"Appending Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
|
||||
/*
|
||||
** append node before the last one
|
||||
*/
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
addr->name=strdup("Babs Jensen");
|
||||
addr->city=strdup("Cupertino");
|
||||
addr->state=strdup("CA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
new=allocateNode((void *) addr);
|
||||
appendNodeSorted(&head,&new,compFunc);
|
||||
(void) fprintf(stderr,"Appending Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
/*
|
||||
** print
|
||||
*/
|
||||
(void) fprintf(stderr,"\n---------------[ printing ]----------\n");
|
||||
n=0;
|
||||
for (l=head; l; l=l->next)
|
||||
{
|
||||
addr=(Addr *) l->data;
|
||||
(void) fprintf(stderr,"Node: %d\n",++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
}
|
||||
|
||||
/*
|
||||
** free nodes
|
||||
*/
|
||||
(void) fprintf(stderr,"\n---------------[ freeing ]----------\n");
|
||||
destroyNodes(&head,freeData);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** routine to free the user data
|
||||
*/
|
||||
|
||||
static void freeData(void **data)
|
||||
{
|
||||
Addr
|
||||
**addr=(Addr **) data;
|
||||
|
||||
static int
|
||||
n=0;
|
||||
|
||||
n++;
|
||||
if (*addr)
|
||||
{
|
||||
if ((*addr)->name)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->name);
|
||||
(void) free((char *) (*addr)->name);
|
||||
}
|
||||
if ((*addr)->city)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->city);
|
||||
(void) free ((char *) (*addr)->city);
|
||||
}
|
||||
if ((*addr)->state)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->state);
|
||||
(void) free ((char *) (*addr)->state);
|
||||
}
|
||||
|
||||
(void) fprintf(stderr,"Freeing the node %d itself\n\n",n);
|
||||
(void) free((char *) (*addr));
|
||||
(*addr)=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int compFunc(void *a1,void *a2)
|
||||
{
|
||||
Addr
|
||||
*addr1=(Addr *) a1,
|
||||
*addr2=(Addr *) a2;
|
||||
|
||||
/*
|
||||
(void) fprintf(stderr,"name1=%s\n",addr1->name);
|
||||
(void) fprintf(stderr,"name2=%s\n",addr2->name);
|
||||
*/
|
||||
#ifdef WINNT
|
||||
return (stricmp(addr1->name,addr2->name));
|
||||
#else
|
||||
return (strcasecmp(addr1->name,addr2->name));
|
||||
#endif /* ! WINNT */
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
##
|
||||
# Makefile automatically generated by genmake 1.0, Mar-27-2001
|
||||
# genmake 1.0 by muquit@muquit.com http://www.muquit.com/
|
||||
##
|
||||
CC= cl
|
||||
DEFS= -nologo -G3
|
||||
PROGNAME= apend_sorted
|
||||
LINKER=link -nologo
|
||||
INCLUDES= -I. -I../../
|
||||
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DWINNT=1 -DSYS_WIN32=1 -DHAVE_STRING_H=1 -DHAVE_FCNTL_H=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
SLL_LIB=../../sll.lib
|
||||
LIBS=$(SLL_LIB) user32.lib gdi32.lib winmm.lib comdlg32.lib comctl32.lib
|
||||
RC=rc
|
||||
RCVARS=-r -DWIN32
|
||||
|
||||
SRCS = append_sorted.c
|
||||
|
||||
OBJS = append_sorted.obj
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c $< -Fo$@
|
||||
|
||||
all: $(PROGNAME)
|
||||
|
||||
$(PROGNAME) : $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(PROGNAME)
|
||||
@@ -0,0 +1,31 @@
|
||||
##
|
||||
# Makefile automatically generated by genmake 1.0, Nov-12-98
|
||||
# genmake 1.0 by ma_muquit@fccc.edu, RCS
|
||||
##
|
||||
CC= @CC@
|
||||
DEFS= @DEFS@
|
||||
PROGNAME= sll_delete
|
||||
INCLUDES= -I../..
|
||||
LIBS= -L../../ -lsll
|
||||
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DSYS_UNIX=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
|
||||
SRCS = delete.c
|
||||
|
||||
OBJS = delete.o
|
||||
|
||||
.c.o:
|
||||
rm -f $@
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
all: $(PROGNAME)
|
||||
|
||||
$(PROGNAME) : $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(PROGNAME) core
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
** first append a node at the end of a list. then dele a node and free the
|
||||
** memory associated with data.
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Aug-09-1998 first cut
|
||||
*/
|
||||
|
||||
#include <sll.h>
|
||||
|
||||
typedef struct _addr
|
||||
{
|
||||
char
|
||||
*name,
|
||||
*city,
|
||||
*state;
|
||||
} Addr;
|
||||
|
||||
static void freeData(void **data);
|
||||
|
||||
int main (int argc,char **argv)
|
||||
{
|
||||
Sll
|
||||
*node,
|
||||
*l,
|
||||
*head=NULL,
|
||||
*new=NULL;
|
||||
Addr
|
||||
*addr;
|
||||
|
||||
int
|
||||
n=0;
|
||||
|
||||
(void) fprintf(stderr,
|
||||
"=========================================================================\n");
|
||||
(void) fprintf(stderr," Append a node at the beginning of a list\n");
|
||||
(void) fprintf(stderr,
|
||||
"=========================================================================\n");
|
||||
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
(void) fprintf(stderr,"\n---------------[ appending ]----------\n");
|
||||
/*
|
||||
** it will be the last node
|
||||
*/
|
||||
addr->name=strdup("Muhammad A Muquit");
|
||||
addr->city=strdup("Philadelphia");
|
||||
addr->state=strdup("PA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
new=allocateNode((void *) addr);
|
||||
appendNode(&head,&new);
|
||||
(void) fprintf(stderr,"Appending Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
/*
|
||||
** append node before the last one
|
||||
*/
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
addr->name=strdup("Janet Hunter");
|
||||
addr->city=strdup("Santa Clara");
|
||||
addr->state=strdup("CA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
new=allocateNode((void *) addr);
|
||||
appendNode(&head,&new);
|
||||
(void) fprintf(stderr,"Appending Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
|
||||
/*
|
||||
** append node before the last one
|
||||
*/
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
addr->name=strdup("Babs Jensen");
|
||||
addr->city=strdup("Cupertino");
|
||||
addr->state=strdup("CA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
new=allocateNode((void *) addr);
|
||||
appendNode(&head,&new);
|
||||
(void) fprintf(stderr,"Appending Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
/*
|
||||
** print
|
||||
*/
|
||||
(void) fprintf(stderr,"\n---------------[ printing ]----------\n");
|
||||
n=0;
|
||||
for (l=head; l; l=l->next)
|
||||
{
|
||||
addr=(Addr *) l->data;
|
||||
(void) fprintf(stderr,"Node: %d\n",++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
}
|
||||
|
||||
(void) fprintf(stderr,"\n-----------[ delete Node 2 ]---------\n");
|
||||
node=getNthNode(head,2);
|
||||
if (node != NULL)
|
||||
destroyNode(&head,node,freeData);
|
||||
else
|
||||
(void) fprintf(stderr,"No node found at position 2\n");
|
||||
(void) fprintf(stderr,"\n-----------[ printing all the nodes again ]--------\n");
|
||||
n=0;
|
||||
for (l=head; l; l=l->next)
|
||||
{
|
||||
addr=(Addr *) l->data;
|
||||
(void) fprintf(stderr,"Node: %d\n",++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** free nodes
|
||||
*/
|
||||
(void) fprintf(stderr,"\n---------------[ freeing ]----------\n");
|
||||
destroyNodes(&head,freeData);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** routine to free the user data
|
||||
*/
|
||||
|
||||
static void freeData(void **data)
|
||||
{
|
||||
Addr
|
||||
**addr=(Addr **) data;
|
||||
|
||||
if (*addr)
|
||||
{
|
||||
if ((*addr)->name)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->name);
|
||||
(void) free((char *) (*addr)->name);
|
||||
}
|
||||
if ((*addr)->city)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->city);
|
||||
(void) free ((char *) (*addr)->city);
|
||||
}
|
||||
if ((*addr)->state)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->state);
|
||||
(void) free ((char *) (*addr)->state);
|
||||
}
|
||||
|
||||
(void) fprintf(stderr,"Freeing the node itself\n\n");
|
||||
(void) free((char *) (*addr));
|
||||
(*addr)=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
##
|
||||
# Makefile automatically generated by genmake 1.0, Mar-27-2001
|
||||
# genmake 1.0 by muquit@muquit.com http://www.muquit.com/
|
||||
##
|
||||
CC= cl
|
||||
DEFS= -nologo -G3
|
||||
PROGNAME= delete
|
||||
LINKER=link -nologo
|
||||
INCLUDES= -I. -I../../
|
||||
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DWINNT=1 -DSYS_WIN32=1 -DHAVE_STRING_H=1 -DHAVE_FCNTL_H=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
SLL_LIB=../../sll.lib
|
||||
LIBS=$(SLL_LIB) user32.lib gdi32.lib winmm.lib comdlg32.lib comctl32.lib
|
||||
RC=rc
|
||||
RCVARS=-r -DWIN32
|
||||
|
||||
SRCS = delete.c
|
||||
|
||||
OBJS = delete.obj
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c $< -Fo$@
|
||||
|
||||
all: $(PROGNAME)
|
||||
|
||||
$(PROGNAME) : $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(PROGNAME)
|
||||
@@ -0,0 +1,31 @@
|
||||
##
|
||||
# Makefile automatically generated by genmake 1.0, Nov-12-98
|
||||
# genmake 1.0 by ma_muquit@fccc.edu, RCS
|
||||
##
|
||||
CC= @CC@
|
||||
DEFS= @DEFS@
|
||||
PROGNAME= sll_insert
|
||||
INCLUDES= -I../..
|
||||
LIBS= -L../../ -lsll
|
||||
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DSYS_UNIX=1
|
||||
CFLAGS= -O $(DEFINES)
|
||||
|
||||
SRCS = insert.c
|
||||
|
||||
OBJS = insert.o
|
||||
|
||||
.c.o:
|
||||
rm -f $@
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
all: $(PROGNAME)
|
||||
|
||||
$(PROGNAME) : $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(PROGNAME) core
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
** test inserting a node at the beginning of the list. print the result
|
||||
** and then free the memory. a user defined function is called to free
|
||||
** the data.
|
||||
**
|
||||
** Development History:
|
||||
** who when why
|
||||
** ma_muquit@fccc.edu Aug-09-1998 first cut
|
||||
*/
|
||||
|
||||
|
||||
#include <sll.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct _addr
|
||||
{
|
||||
char
|
||||
*name,
|
||||
*city,
|
||||
*state;
|
||||
} Addr;
|
||||
|
||||
static void freeData(void **data);
|
||||
|
||||
int main (int argc,char **argv)
|
||||
{
|
||||
Sll
|
||||
*l,
|
||||
*head=NULL,
|
||||
*new=NULL;
|
||||
Addr
|
||||
*addr;
|
||||
|
||||
int
|
||||
n=0;
|
||||
|
||||
(void) fprintf(stderr,
|
||||
"=========================================================================\n");
|
||||
(void) fprintf(stderr," Testing Insert a node at the beginning of a list\n");
|
||||
(void) fprintf(stderr,
|
||||
"=========================================================================\n");
|
||||
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
** it will be the last node
|
||||
*/
|
||||
addr->name=strdup("Muhammad A Muquit");
|
||||
addr->city=strdup("Philadelphia");
|
||||
addr->state=strdup("PA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
new=allocateNode((void *) addr);
|
||||
insertNode(&head,&new);
|
||||
(void) fprintf(stderr,"Inserting Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
/*
|
||||
** insert node before the last one
|
||||
*/
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
addr->name=strdup("Janet Hunter");
|
||||
addr->city=strdup("Santa Clara");
|
||||
addr->state=strdup("CA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
new=allocateNode((void *) addr);
|
||||
insertNode(&head,&new);
|
||||
(void) fprintf(stderr,"Inserting Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
|
||||
/*
|
||||
** insert node before the last one
|
||||
*/
|
||||
addr=(Addr *) malloc(sizeof(Addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
(void) fprintf(stderr," malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
addr->name=strdup("Babs Jensen");
|
||||
addr->city=strdup("Cupertino");
|
||||
addr->state=strdup("CA");
|
||||
|
||||
if ((addr->name == NULL) ||
|
||||
(addr->city == NULL) ||
|
||||
(addr->state == NULL))
|
||||
{
|
||||
(void) fprintf(stderr,"malloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
new=allocateNode((void *) addr);
|
||||
insertNode(&head,&new);
|
||||
(void) fprintf(stderr,"Inserting Node: %d\n", ++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n",addr->state);
|
||||
|
||||
/*
|
||||
** print
|
||||
*/
|
||||
(void) fprintf(stderr,"\n\nPrinting........\n");
|
||||
n=0;
|
||||
for (l=head; l; l=l->next)
|
||||
{
|
||||
addr=(Addr *) l->data;
|
||||
(void) fprintf(stderr,"Node: %d\n",++n);
|
||||
(void) fprintf(stderr," %s\n",addr->name);
|
||||
(void) fprintf(stderr," %s\n",addr->city);
|
||||
(void) fprintf(stderr," %s\n\n",addr->state);
|
||||
}
|
||||
|
||||
/*
|
||||
** free nodes
|
||||
*/
|
||||
destroyNodes(&head,freeData);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** routine to free the user data
|
||||
*/
|
||||
|
||||
static void freeData(void **data)
|
||||
{
|
||||
Addr
|
||||
**addr=(Addr **) data;
|
||||
|
||||
static int
|
||||
n=0;
|
||||
|
||||
n++;
|
||||
if (*addr)
|
||||
{
|
||||
if ((*addr)->name)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->name);
|
||||
(void) free((char *) (*addr)->name);
|
||||
}
|
||||
if ((*addr)->city)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->city);
|
||||
(void) free ((char *) (*addr)->city);
|
||||
}
|
||||
if ((*addr)->state)
|
||||
{
|
||||
(void) fprintf(stderr," Freeing: %s\n",(*addr)->state);
|
||||
(void) free ((char *) (*addr)->state);
|
||||
}
|
||||
|
||||
(void) fprintf(stderr,"Freeing the node %d itself\n\n",n);
|
||||
(void) free((char *) (*addr));
|
||||
(*addr)=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
##
|
||||
# Makefile automatically generated by genmake 1.0, Mar-27-2001
|
||||
# genmake 1.0 by muquit@muquit.com http://www.muquit.com/
|
||||
##
|
||||
CC= cl
|
||||
DEFS= -nologo -G3
|
||||
PROGNAME= insert
|
||||
LINKER=link -nologo
|
||||
INCLUDES= -I. -I../../
|
||||
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS) -DWINNT=1 -DSYS_WIN32=1 -DHAVE_STRING_H=1 -DHAVE_FCNTL_H=1
|
||||
|
||||
CFLAGS= -O $(DEFINES)
|
||||
SLL_LIB= ../../sll.lib
|
||||
LIBS=$(SLL_LIB) user32.lib gdi32.lib winmm.lib comdlg32.lib comctl32.lib
|
||||
RC=rc
|
||||
RCVARS=-r -DWIN32
|
||||
|
||||
SRCS = insert.c
|
||||
|
||||
OBJS = insert.obj
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c $< -Fo$@
|
||||
|
||||
all: $(PROGNAME)
|
||||
|
||||
$(PROGNAME) : $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(PROGNAME)
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
function description of singly linked list library
|
||||
|
||||
|
||||
Data structure
|
||||
--------------
|
||||
|
||||
typedef struct _Sll
|
||||
{
|
||||
void
|
||||
*data; /* void pointer for user data */
|
||||
|
||||
struct _Sll
|
||||
*next; /* pointer to next node */
|
||||
} Sll;
|
||||
|
||||
Functions description
|
||||
=====================
|
||||
|
||||
void initList (Sll **list);
|
||||
Initializes *list by setting the list pointer to NULL.
|
||||
|
||||
Sll *allocateNode (void *data);
|
||||
Allocates space for a new node and initializes the data fields. The user
|
||||
is responsible for passing a valid pointer to data. The pointer to data
|
||||
can be anything. If a large amount data needs to used, put all the data
|
||||
in a structure and send pointer to a structure.
|
||||
|
||||
void appendNode(Sll **head,Sll **new)
|
||||
Appends a node to the end of a list. list gets modified and new is the
|
||||
node to be appended.
|
||||
|
||||
void appendNodeSorted(Sll **head,Sll **new,Ifunc compFunc);
|
||||
Appends a node to the end of a list sorted. The data of two lists are
|
||||
passwd to the user defined function compFunction for sorting. The function
|
||||
returns an integer 0 or > 0.
|
||||
|
||||
void insertNode(Sll **head,Sll **new)
|
||||
Insert a node at the beginning of a list. Insert node new at the beginning
|
||||
of list "list". Note, the list "list" gets modified.
|
||||
|
||||
Bool emptyList(Sll *list)
|
||||
Checks if a list is empty.
|
||||
|
||||
void delNode(Sll **head,Sll *node)
|
||||
Deletes a node from the list. "lsit" is the list to modify and node is the
|
||||
node to remove.
|
||||
|
||||
void freeNode(Sll **list)
|
||||
Frees a node. It does not do free the data. It checks before freeing if
|
||||
the list is NULL or not. If not NULL, it will be freed. Therefore, list
|
||||
must point to a valid location in memory.
|
||||
|
||||
Sll *getNthNode(Sll *head,int n)
|
||||
Returns the nth node in a list. Node starts at 1. If there is no such
|
||||
node, NULL is returned.
|
||||
|
||||
void destroyNode(Sll **head,Sll *node,void (*freeFunc)(void **))
|
||||
head -- the entire list, gets modifed
|
||||
node -- the node to destroy
|
||||
freeFunc -- the function to call to free the data.
|
||||
|
||||
Frees memory allocated for a node and the data associated with the
|
||||
node. The caller is responsible to write the function to free the memory
|
||||
for the data.
|
||||
|
||||
void destroyNodes(Sll **head,void (*freeFunc)(void **))
|
||||
head -- the head node of the list
|
||||
freeFunc - function to free data
|
||||
|
||||
Fress the entire list and the data. The caller is responsible to write the
|
||||
function to free data and pass it in the function.
|
||||
|
||||
int numNodes(Sll **head)
|
||||
Returns number of nodes in the list.
|
||||
|
||||
--
|
||||
Muhammad A Muquit
|
||||
Aug-09-1998
|
||||
Saturday
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#--------------------------------------------
|
||||
# Makefile for MS Visual C++
|
||||
# muquit@muquit.com
|
||||
#--------------------------------------------
|
||||
|
||||
CC= cl /MD
|
||||
DEFS= -DWINNT=1 -DSTRICT_MODE=1 -DHAVE_STRING_H=1 -DHAVE_FCNTL_H=1
|
||||
|
||||
INCLUDES= -I.
|
||||
LIBRARY=sll.lib
|
||||
|
||||
# replace -O with -g in order to debug
|
||||
|
||||
DEFINES= $(INCLUDES) $(DEFS)
|
||||
#CFLAGS= $(cvars) $(cdebug) -nologo -G4 $(DEFINES)
|
||||
|
||||
|
||||
SRCS = sll.c
|
||||
OBJS = sll.obj
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c $< -Fo$@
|
||||
|
||||
all: $(LIBRARY)
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
link /lib /OUT:$(LIBRARY) $(OBJS)
|
||||
|
||||
clean:
|
||||
del $(OBJS) $(LIBRARY) *.bak
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# create a gzip compressed tar archive of the current working directory.
|
||||
# the name of the file will be dir.tar.gz
|
||||
#
|
||||
|
||||
. ./VERSION
|
||||
|
||||
pwd=`pwd`
|
||||
pwd_head=`basename $pwd`
|
||||
|
||||
#
|
||||
# first check if we'r at the corrent directory
|
||||
#
|
||||
|
||||
if [ $pwd_head != $SLL_VERSION ]; then
|
||||
echo "You are in wrong base directory"
|
||||
echo "Expected: $SLL_VERSION"
|
||||
echo "Found: $pwd_head"
|
||||
echo "exiting ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
tar_filename=$pwd_head.tar
|
||||
#
|
||||
# remove the tar file if any in the current working directoyr
|
||||
#
|
||||
if [ -f ./$tar_filename.gz ]; then
|
||||
echo "removing $tar_filename.gz"
|
||||
rm -f ./$tar_filename.gz
|
||||
fi
|
||||
|
||||
make clean > /dev/null 2>&1
|
||||
#
|
||||
# go up
|
||||
#
|
||||
|
||||
cd ..
|
||||
tar -cf /tmp/$tar_filename ./$pwd_head
|
||||
if [ $? -eq 0 ]; then
|
||||
gzip -f -v -9 /tmp/$tar_filename
|
||||
mv /tmp/$tar_filename.gz ./$pwd_head
|
||||
cd $pwd
|
||||
ls -l $tar_filename.gz
|
||||
fi
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Styles for the base documents used by the CGI RFC project.
|
||||
*/
|
||||
|
||||
BODY
|
||||
{
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
/*
|
||||
* Standard styles for marking up drafts and RFC documents.
|
||||
*/
|
||||
|
||||
.shabuj
|
||||
{
|
||||
color: green;
|
||||
}
|
||||
|
||||
.lal
|
||||
{
|
||||
color: red;
|
||||
}
|
||||
|
||||
.fuchsia
|
||||
{
|
||||
color: fuchsia;
|
||||
}
|
||||
Reference in New Issue
Block a user