mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Release calc version 2.10.3t5.45
This commit is contained in:
503
sample/Makefile
Normal file
503
sample/Makefile
Normal file
@@ -0,0 +1,503 @@
|
||||
#
|
||||
# sample - makefile for calc sample programs
|
||||
#
|
||||
# Copyright (c) 1997 Landon Curt Noll
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and
|
||||
# its documentation for any purpose and without fee is hereby granted,
|
||||
# provided that the above copyright, this permission notice and text
|
||||
# this comment, and the disclaimer below appear in all of the following:
|
||||
#
|
||||
# supporting documentation
|
||||
# source copies
|
||||
# source works derived from this source
|
||||
# binaries derived from this source or from derived source
|
||||
#
|
||||
# LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
||||
# EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
# PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
# Comments, suggestions, bug fixes and questions about these routines
|
||||
# are welcome. Send EMail to the address given below.
|
||||
#
|
||||
# Happy bit twiddling,
|
||||
#
|
||||
# Landon Curt Noll
|
||||
#
|
||||
# chongo@toad.com
|
||||
# ...!{pyramid,sun,uunet}!hoptoad!chongo
|
||||
#
|
||||
# chongo was here /\../\
|
||||
|
||||
##############################################################################
|
||||
#-=-=-=-=-=-=-=-=- You may want to change some values below -=-=-=-=-=-=-=-=-#
|
||||
##############################################################################
|
||||
|
||||
# Any .h files that are needed by programs that use libcustcalc.a
|
||||
# Don't put ${REQUIRED_H_SRC} files in this list.
|
||||
#
|
||||
# Put any .h files that you add which might be useful to other
|
||||
# programs here.
|
||||
#
|
||||
SAMPLE_H_SRC=
|
||||
|
||||
# Any .c files that are needed to build libcustcalc.a.
|
||||
# Don't put ${REQUIRED_SRC} files in this list.
|
||||
#
|
||||
# There MUST be a .c in SAMPLE_SRC for every .o in SAMPLE_OBJ.
|
||||
#
|
||||
# Put your sample .c files here.
|
||||
#
|
||||
SAMPLE_SRC= many_random.c test_random.c
|
||||
|
||||
# Any .o files that are needed by program that use libcustcalc.a.
|
||||
# Don't put ${REQUIRED_OBJ} files in this list.
|
||||
#
|
||||
# There MUST be a .c in SAMPLE_SRC for every .o in SAMPLE_OBJ.
|
||||
#
|
||||
# Put your sample .o files here.
|
||||
#
|
||||
SAMPLE_OBJ= many_random.o test_random.o
|
||||
|
||||
##############################################################################
|
||||
#-=-=-=-=-=-=- Defaults in case you want to build from this dir -=-=-=-=-=-=-#
|
||||
##############################################################################
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# Makefile debug
|
||||
#
|
||||
# Q=@ do not echo internal makefile actions (quiet mode)
|
||||
# Q= echo internal makefile actions (debug / verbose mode)
|
||||
#
|
||||
#Q=
|
||||
Q=@
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# where to install things
|
||||
#
|
||||
# ${TOPDIR} is the directory under which the calc directory will be placed.
|
||||
# ${LIBDIR} is where the *.cal, *.h, *.a, bindings and help dir are installed.
|
||||
# ${HELPDIR} is where the help directory is installed.
|
||||
#
|
||||
TOPDIR= /usr/local/lib
|
||||
#TOPDIR= /usr/lib
|
||||
#TOPDIR= /usr/libdata
|
||||
#TOPDIR= /usr/contrib/lib
|
||||
#
|
||||
LIBDIR= ${TOPDIR}/calc
|
||||
HELPDIR= ${LIBDIR}/help
|
||||
|
||||
# The return value type of main() differs from platform to platform.
|
||||
# In some cases, a compiler warning is issued because main() does
|
||||
# or does not return a value.
|
||||
#
|
||||
# MAIN= -DMAIN=void main() is of type void
|
||||
# MAIN= -DMAIN=int main() is of type int
|
||||
#
|
||||
# When in doubt, try MAIN= -DMAIN=void. If you get a warning try the other.
|
||||
#
|
||||
MAIN= -DMAIN=void
|
||||
#MAIN= -DMAIN=int
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# Debug/Optimize options for ${CC}
|
||||
#
|
||||
DEBUG= -O
|
||||
#DEBUG= -O -g
|
||||
#DEBUG= -O -g3
|
||||
#DEBUG= -O1
|
||||
#DEBUG= -O1 -g
|
||||
#DEBUG= -O1 -g3
|
||||
#DEBUG= -O2
|
||||
#DEBUG= -O2 -g
|
||||
#DEBUG= -O2 -g3
|
||||
#DEBUG= -O2 -ipa
|
||||
#DEBUG= -O2 -g3 -ipa
|
||||
#DEBUG= -O3
|
||||
#DEBUG= -O3 -g
|
||||
#DEBUG= -O3 -g3
|
||||
#DEBUG= -O3 -ipa
|
||||
#DEBUG= -O3 -g3 -ipa
|
||||
#DEBUG= -g
|
||||
#DEBUG= -g3
|
||||
#DEBUG= -gx
|
||||
#DEBUG= -WM,-g
|
||||
#DEBUG=
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# On systems that have dynamic shared libs, you may want want to disable them
|
||||
# for faster calc startup.
|
||||
#
|
||||
# System type NO_SHARED recommendation
|
||||
#
|
||||
# BSD NO_SHARED=
|
||||
# SYSV NO_SHARED= -dn
|
||||
# IRIX NO_SHARED= -non_shared
|
||||
# disable NO_SHARED=
|
||||
#
|
||||
# If in doubt, use NO_SHARED=
|
||||
#
|
||||
NO_SHARED=
|
||||
#NO_SHARED= -dn
|
||||
#NO_SHARED= -non_shared
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# Some systems require one to use ranlib to add a symbol table to
|
||||
# a *.a library. Set RANLIB to the utility that performs this action.
|
||||
# Set RANLIB to : if your system does not need such a utility.
|
||||
#
|
||||
#RANLIB=ranlib
|
||||
RANLIB=:
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# Normally certain files depend on the Makefile. If the Makefile is
|
||||
# changed, then certain steps should be redone. If MAKE_FILE is
|
||||
# set to Makefile, then these files will depend on Makefile. If
|
||||
# MAKE_FILE is empty, they they wont.
|
||||
#
|
||||
# If in doubt, set MAKE_FILE to Makefile
|
||||
#
|
||||
MAKE_FILE= Makefile
|
||||
#MAKE_FILE=
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# If you do not wish to use purify, leave PURIFY commented out.
|
||||
#
|
||||
# If in doubt, leave PURIFY commented out.
|
||||
#
|
||||
#PURIFY= purify -logfile=pure.out
|
||||
#PURIFY= purify
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# By default, custom builtin functions may only be executed if calc
|
||||
# is given the -C option. This is because custom builtin functions
|
||||
# may invoke non-standard or non-portable code. One may completely
|
||||
# disable custom builtin functions by not compiling any of code
|
||||
#
|
||||
# ALLOW_CUSTOM= -DCUSTOM # allow custom only if -C is given
|
||||
# ALLOW_CUSTOM= # disable custom even if -C is given
|
||||
#
|
||||
# If in doubt, use ALLOW_CUSTOM= -DCUSTOM
|
||||
#
|
||||
ALLOW_CUSTOM= -DCUSTOM
|
||||
#ALLOW_CUSTOM=
|
||||
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# The sample routines need to be compiled with libcalc.a. The ${CALC_LIBS}
|
||||
# variable tells where this library may be found
|
||||
#
|
||||
# CALC_LIBS= ../libcalc.a ... # compile with libcalc.a in dir above
|
||||
# CALC_LIBS= ${LIBDIR}/libcalc.a ... # compile the installed libcalc.a
|
||||
# CALC_LIBS= -lcalc ... # compile with the system libcalc.a
|
||||
#
|
||||
# If in doubt, use CALC_LIBS= ../libcalc.a
|
||||
#
|
||||
CALC_LIBS= ../libcalc.a ../custom/libcustcalc.a
|
||||
#CALC_LIBS= ${LIBDIR}/libcalc.a ${LIBDIR}/libcustcalc.a
|
||||
#CALC_LIBS= -lcalc -lcustcalc
|
||||
|
||||
###
|
||||
#
|
||||
# Normally, the upper level makefile will set these values. We provide
|
||||
# a default here just in case you want to build from this directory.
|
||||
#
|
||||
# Select your compiler type by commenting out one of the cc sets below:
|
||||
#
|
||||
# CCOPT are flags given to ${CC} for optimization
|
||||
# CCWARN are flags given to ${CC} for warning message control
|
||||
# CCMISC are misc flags given to ${CC}
|
||||
#
|
||||
# CFLAGS are all flags given to ${CC} [[often includes CCOPT, CCWARN, CCMISC]]
|
||||
# ICFLAGS are given to ${CC} for intermediate progs
|
||||
#
|
||||
# CCMAIN are flags for ${CC} when files with main() instead of CFLAGS
|
||||
#
|
||||
# LCFLAGS are CC-style flags for ${LINT}
|
||||
# LDFLAGS are flags given to ${CC} for linking .o files
|
||||
# ILDFLAGS are flags given to ${CC} for linking .o files for intermediate progs
|
||||
#
|
||||
# CC is how the the C compiler is invoked
|
||||
#
|
||||
###
|
||||
#
|
||||
# common cc set
|
||||
#
|
||||
CCWARN=
|
||||
CCOPT= ${DEBUG} ${NO_SHARED}
|
||||
CCMISC=
|
||||
#
|
||||
CFLAGS= ${CCWARN} ${CCOPT} ${CCMISC} ${ALLOW_CUSTOM}
|
||||
ICFLAGS= ${CCWARN} ${CCMISC}
|
||||
#
|
||||
CCMAIN= ${ICFLAGS} ${MAIN}
|
||||
#
|
||||
LCFLAGS=
|
||||
LDFLAGS= ${NO_SHARED} ${LD_NO_SHARED}
|
||||
ILDFLAGS=
|
||||
#
|
||||
CC= ${PURIFY} cc
|
||||
|
||||
##############################################################################
|
||||
#-=-=-=-=-=-=-=-=- Be careful if you change something below -=-=-=-=-=-=-=-=-#
|
||||
##############################################################################
|
||||
|
||||
# These .c files are used to build the dependency list
|
||||
#
|
||||
C_SRC= ${SAMPLE_SRC}
|
||||
|
||||
# These .h files are used to build the dependecy list
|
||||
#
|
||||
H_SRC= ${SAMPLE_H_SRC}
|
||||
|
||||
# These files are found (but not built) in the distribution
|
||||
#
|
||||
# The SAMPLE_CAL and HOW_TO_ADD are files distributed from this
|
||||
# directory but are installed as help files from the help/Makefile.
|
||||
#
|
||||
DISTLIST= ${C_SRC} ${H_SRC} ${MAKE_FILE} README_SAMPLE
|
||||
|
||||
# complete list of targets
|
||||
#
|
||||
TARGETS= many_random test_random
|
||||
|
||||
# required vars
|
||||
#
|
||||
SHELL = /bin/sh
|
||||
SED= sed
|
||||
MAKEDEPEND= makedepend
|
||||
SORT= sort
|
||||
|
||||
##
|
||||
#
|
||||
# Standard rules and targets
|
||||
#
|
||||
##
|
||||
|
||||
all: ${TARGETS} .all
|
||||
|
||||
test_random.o: test_random.c
|
||||
${CC} ${CCMAIN} ${CCOPT} ${ALLOW_CUSTOM} test_random.c -c
|
||||
|
||||
test_random: test_random.o ../libcalc.a
|
||||
${CC} ${LDFLAGS} test_random.o ${CALC_LIBS} ${LD_DEBUG} -o test_random
|
||||
|
||||
many_random.o: many_random.c
|
||||
${CC} ${CCMAIN} ${CCOPT} ${ALLOW_CUSTOM} many_random.c -c
|
||||
|
||||
many_random: many_random.o ../libcalc.a
|
||||
${CC} ${LDFLAGS} many_random.o ${CALC_LIBS} ${LD_DEBUG} -o many_random
|
||||
|
||||
##
|
||||
#
|
||||
# used by the upper level Makefile
|
||||
#
|
||||
##
|
||||
|
||||
# to determine of we have done all
|
||||
#
|
||||
.all:
|
||||
rm -f .all
|
||||
touch .all
|
||||
|
||||
##
|
||||
#
|
||||
# File list generation. You can ignore this section.
|
||||
#
|
||||
#
|
||||
# We will form the names of source files as if they were in a
|
||||
# sub-directory called calc/lib.
|
||||
#
|
||||
# NOTE: Due to bogus shells found on one common system we must have
|
||||
# an non-emoty else clause for every if condition. *sigh*
|
||||
#
|
||||
##
|
||||
|
||||
distlist: ${DISTLIST}
|
||||
${Q}for i in ${DISTLIST}; do \
|
||||
echo calc/sample/$$i; \
|
||||
done
|
||||
|
||||
# The bsdi distribution has generated files as well as distributed files.
|
||||
#
|
||||
bsdilist: ${DISTLIST}
|
||||
${Q}for i in ${DISTLIST}; do \
|
||||
echo calc/sample/$$i; \
|
||||
done
|
||||
|
||||
##
|
||||
#
|
||||
# Home grown make dependency rules. Your system make not support
|
||||
# or have the needed tools. You can ignore this section.
|
||||
#
|
||||
# We will form a skelaton tree of *.c files containing only #include "foo.h"
|
||||
# lines and .h files containing the same lines surrounded by multiple include
|
||||
# prevention lines. This allows us to build a static depend list that will
|
||||
# satisfy all possible cpp symbol definition combinations.
|
||||
#
|
||||
##
|
||||
|
||||
depend:
|
||||
${Q}if [ -f Makefile.bak ]; then \
|
||||
echo "Makefile.bak exists, remove or move it out of the way"; \
|
||||
exit 1; \
|
||||
else \
|
||||
true; \
|
||||
fi
|
||||
${Q}echo forming sample/skel
|
||||
-${Q}rm -rf skel
|
||||
${Q}mkdir skel
|
||||
${Q}mkdir skel/sample
|
||||
-${Q}for i in ${C_SRC}; do \
|
||||
${SED} -n '/^#[ ]*include[ ]*"/p' \
|
||||
"$$i" > "skel/sample/$$i"; \
|
||||
done
|
||||
-${Q}for i in ${H_SRC} /dev/null; do \
|
||||
if [ X"$$i" != X"/dev/null" ]; then \
|
||||
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
|
||||
echo "#ifndef $$tag" > "skel/sample/$$i"; \
|
||||
echo "#define $$tag" >> "skel/sample/$$i"; \
|
||||
${SED} -n '/^#[ ]*include[ ]*"/p' "$$i" \
|
||||
>> "skel/sample/$$i"; \
|
||||
echo '#endif /* '"$$tag"' */' >> "skel/sample/$$i"; \
|
||||
fi; \
|
||||
done
|
||||
${Q}(cd ..; ${MAKE} hsrc)
|
||||
${Q}for i in `cd ..; ${MAKE} h_list`; do \
|
||||
tag="`echo $$i | ${SED} 's/[\.+,:]/_/g'`"; \
|
||||
echo "#ifndef $$tag" > "skel/$$i"; \
|
||||
echo "#define $$tag" >> "skel/$$i"; \
|
||||
${SED} -n '/^#[ ]*include[ ]*"/p' "../$$i" \
|
||||
>> "skel/$$i"; \
|
||||
echo '#endif /* '"$$tag"' */' >> "skel/$$i"; \
|
||||
done
|
||||
-${Q}rm -f skel/sample/makedep.out
|
||||
${Q}echo sample/skel formed
|
||||
${Q}echo forming sample dependency list
|
||||
${Q}echo "# DO NOT DELETE THIS LINE -- make depend depends on it." > \
|
||||
skel/sample/makedep.out
|
||||
${Q}cd skel/sample; ${MAKEDEPEND} -w 1 -m -f makedep.out -I.. ${C_SRC}
|
||||
-${Q}for i in ${C_SRC}; do \
|
||||
echo "$$i" | \
|
||||
${SED} 's/^\(.*\)\.c/\1.o: \1.c/' \
|
||||
>> skel/sample/makedep.out; \
|
||||
done
|
||||
${Q}echo sample dependency list formed
|
||||
${Q}echo forming new sample/Makefile
|
||||
-${Q}rm -f Makefile.bak
|
||||
${Q}mv Makefile Makefile.bak
|
||||
${Q}${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak > Makefile
|
||||
${Q}echo "" >> Makefile
|
||||
${Q}${SED} -n '3,$$p' skel/sample/makedep.out | ${SORT} -u >> Makefile
|
||||
-${Q}rm -rf skel
|
||||
-${Q}if cmp -s Makefile.bak Makefile; then \
|
||||
echo 'sample Makefile was already up to date'; \
|
||||
mv -f Makefile.bak Makefile; \
|
||||
else \
|
||||
rm -f Makefile.tmp; \
|
||||
mv Makefile Makefile.tmp; \
|
||||
sccs edit Makefile; \
|
||||
mv Makefile.tmp Makefile; \
|
||||
echo new 'sample Makefile formed -- you need to check it in'; \
|
||||
fi
|
||||
|
||||
##
|
||||
#
|
||||
# Utility rules
|
||||
#
|
||||
##
|
||||
|
||||
clean:
|
||||
-rm -f ${SAMPLE_OBJ} core
|
||||
|
||||
clobber:
|
||||
-rm -f ${SAMPLE_OBJ}
|
||||
-rm -f ${TARGETS}
|
||||
rm -f .all Makefile.tmp sample
|
||||
|
||||
# for right now we will not install anything
|
||||
install: all
|
||||
|
||||
##
|
||||
#
|
||||
# make depend stuff
|
||||
#
|
||||
##
|
||||
|
||||
# DO NOT DELETE THIS LINE
|
||||
|
||||
many_random.o: ../alloc.h
|
||||
many_random.o: ../block.h
|
||||
many_random.o: ../byteswap.h
|
||||
many_random.o: ../calc.h
|
||||
many_random.o: ../calcerr.h
|
||||
many_random.o: ../cmath.h
|
||||
many_random.o: ../config.h
|
||||
many_random.o: ../endian_calc.h
|
||||
many_random.o: ../hash.h
|
||||
many_random.o: ../have_const.h
|
||||
many_random.o: ../have_malloc.h
|
||||
many_random.o: ../have_memmv.h
|
||||
many_random.o: ../have_newstr.h
|
||||
many_random.o: ../have_stdlib.h
|
||||
many_random.o: ../have_string.h
|
||||
many_random.o: ../lib_util.h
|
||||
many_random.o: ../longbits.h
|
||||
many_random.o: ../md5.h
|
||||
many_random.o: ../nametype.h
|
||||
many_random.o: ../qmath.h
|
||||
many_random.o: ../shs.h
|
||||
many_random.o: ../shs1.h
|
||||
many_random.o: ../string.h
|
||||
many_random.o: ../value.h
|
||||
many_random.o: ../zmath.h
|
||||
many_random.o: ../zrandom.h
|
||||
many_random.o: many_random.c
|
||||
test_random.o: ../alloc.h
|
||||
test_random.o: ../block.h
|
||||
test_random.o: ../byteswap.h
|
||||
test_random.o: ../calc.h
|
||||
test_random.o: ../calcerr.h
|
||||
test_random.o: ../cmath.h
|
||||
test_random.o: ../config.h
|
||||
test_random.o: ../endian_calc.h
|
||||
test_random.o: ../hash.h
|
||||
test_random.o: ../have_const.h
|
||||
test_random.o: ../have_malloc.h
|
||||
test_random.o: ../have_memmv.h
|
||||
test_random.o: ../have_newstr.h
|
||||
test_random.o: ../have_stdlib.h
|
||||
test_random.o: ../have_string.h
|
||||
test_random.o: ../lib_util.h
|
||||
test_random.o: ../longbits.h
|
||||
test_random.o: ../md5.h
|
||||
test_random.o: ../nametype.h
|
||||
test_random.o: ../qmath.h
|
||||
test_random.o: ../shs.h
|
||||
test_random.o: ../shs1.h
|
||||
test_random.o: ../string.h
|
||||
test_random.o: ../value.h
|
||||
test_random.o: ../zmath.h
|
||||
test_random.o: ../zrandom.h
|
||||
test_random.o: test_random.c
|
52
sample/README_SAMPLE
Normal file
52
sample/README_SAMPLE
Normal file
@@ -0,0 +1,52 @@
|
||||
This directory contains a few examples of how to use libcalc.a.
|
||||
|
||||
For more details on how to use libcalc.a, see the file ../LIBRARY.
|
||||
|
||||
chongo <share and enjoy :-)> /\oo/\
|
||||
|
||||
=-=
|
||||
|
||||
|
||||
test_random
|
||||
-----------
|
||||
|
||||
Generate random bits using the Blum-Blum-Shub generator that
|
||||
is used by the random() and srandom() builtin functions.
|
||||
|
||||
This prog uses the 10th compiled in Blum modulus.
|
||||
|
||||
This routine makes use of some of the lib_util.c routines.
|
||||
|
||||
usage:
|
||||
|
||||
test_random [bitlen [seed_string]]
|
||||
|
||||
bitlen number of random bits to generate (default: 128 bits)
|
||||
seed_string seed using this ASCII string (default: use default seed)
|
||||
|
||||
|
||||
many_random
|
||||
-----------
|
||||
|
||||
Generate many (100000) sets random bits using the Blum-Blum-Shub
|
||||
generator that is used by the random() and srandom() builtin functions.
|
||||
|
||||
Output is one set per line. Unlike test_random, the seed is not
|
||||
printed. There is no leading 0x on numbers and there is no prefix
|
||||
strings. The only thing printed (normally) is ASCII hex chars and
|
||||
newlines.
|
||||
|
||||
Unlike test_random, this prog will execute for a while. It is
|
||||
useful to watch the process size in order to determine of there
|
||||
is a memory leak.
|
||||
|
||||
This prog uses the 1st compiled in Blum modulus.
|
||||
|
||||
This routine makes use of some of the lib_util.c routines.
|
||||
|
||||
usage:
|
||||
|
||||
many_random [bitlen [seed_string]]
|
||||
|
||||
bitlen number of random bits per line set (default: 128 bits)
|
||||
seed_string seed using this ASCII string (default: use default seed)
|
180
sample/many_random.c
Normal file
180
sample/many_random.c
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* many_random - generate many random values via random number generator
|
||||
*
|
||||
* usage:
|
||||
* many_random [[bits] seed_string]
|
||||
*
|
||||
* seed_string something for which we can seed (def: default seed)
|
||||
* bits number of bits to generate
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 by Landon Curt Noll. All Rights Reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
* provided that the above copyright, this permission notice and text
|
||||
* this comment, and the disclaimer below appear in all of the following:
|
||||
*
|
||||
* supporting documentation
|
||||
* source copies
|
||||
* source works derived from this source
|
||||
* binaries derived from this source or from derived source
|
||||
*
|
||||
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
||||
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* chongo was here /\../\
|
||||
*/
|
||||
|
||||
|
||||
#if defined(__sgi)
|
||||
# include "../longbits.h"
|
||||
# if defined(HAVE_B64)
|
||||
typedef USB64 k_sigset_t;
|
||||
# else
|
||||
typedef struct {
|
||||
USB32 sigbits[2];
|
||||
} k_sigset_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include "../calc.h"
|
||||
#include "../zrandom.h"
|
||||
#include "../have_const.h"
|
||||
#include "../lib_util.h"
|
||||
|
||||
#define DEF_CNT 128 /* default number of bits to generate */
|
||||
#define RESEED 1000 /* number of random numbers to generate */
|
||||
#define MANY 100 /* number of random numbers to generate */
|
||||
|
||||
extern char *program; /* our name */
|
||||
|
||||
|
||||
MAIN
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
RANDOM *prev_state; /* previous random number state */
|
||||
ZVALUE seed; /* seed for Blum-Blum-Shub */
|
||||
ZVALUE tmp; /* temp value */
|
||||
ZVALUE tmp2; /* temp value */
|
||||
ZVALUE random_val; /* random number produced */
|
||||
long cnt; /* number of bits to generate */
|
||||
char *hexstr; /* random number as hex string */
|
||||
int i;
|
||||
int j;
|
||||
|
||||
/*
|
||||
* parse args
|
||||
*/
|
||||
program = argv[0];
|
||||
switch (argc) {
|
||||
case 3:
|
||||
seed = convstr2z(argv[2]);
|
||||
cnt = strtol(argv[1], NULL, 0);
|
||||
break;
|
||||
case 2:
|
||||
seed = _zero_; /* use the default seed */
|
||||
cnt = strtol(argv[1], NULL, 0);
|
||||
break;
|
||||
case 1:
|
||||
seed = _zero_; /* use the default seed */
|
||||
cnt = DEF_CNT;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "usage: %s [[bits] seed_string]\n", program);
|
||||
exit(1);
|
||||
}
|
||||
if (cnt <= 0) {
|
||||
fprintf(stderr, "%s: cnt:%d must be > 0\n", program, (int)cnt);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/*
|
||||
* libcalc setup
|
||||
*/
|
||||
libcalc_call_me_first();
|
||||
|
||||
/*
|
||||
* reseed every so often
|
||||
*/
|
||||
for (j=0; j < RESEED; ++j) {
|
||||
|
||||
/*
|
||||
* seed the generator
|
||||
*/
|
||||
prev_state = zsrandom2(seed, zconst[1]);
|
||||
if (prev_state == NULL) {
|
||||
math_error("previous random state is NULL");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
randomfree(prev_state);
|
||||
|
||||
/*
|
||||
* generate random values forever
|
||||
*/
|
||||
for (i=0; i < MANY; ++i) {
|
||||
|
||||
/*
|
||||
* generate random bits
|
||||
*/
|
||||
zrandom(cnt, &random_val);
|
||||
|
||||
/*
|
||||
* convert into hex string
|
||||
*/
|
||||
hexstr = convz2hex(random_val);
|
||||
printf("%s\n", hexstr);
|
||||
|
||||
/*
|
||||
* free
|
||||
*/
|
||||
if (i < MANY-1) {
|
||||
zfree(random_val);
|
||||
}
|
||||
free(hexstr);
|
||||
}
|
||||
|
||||
/*
|
||||
* increment the seed to better test different seeds
|
||||
*
|
||||
* NOTE: It is generally a bad idea to use the
|
||||
* same random number generator to modify
|
||||
* the seed. We only do this below to
|
||||
* try different seeds for debugging.
|
||||
*
|
||||
* Don't do this in real life applications!
|
||||
*
|
||||
* We want to add at least 2^32 to the seed, so
|
||||
* we do the effect of:
|
||||
*
|
||||
* seed += ((last_val<<32) + last_val);
|
||||
*/
|
||||
zshift(random_val, 32, &tmp);
|
||||
zadd(tmp, random_val, &tmp2);
|
||||
zfree(random_val);
|
||||
zfree(tmp);
|
||||
zadd(seed, tmp2, &tmp);
|
||||
zfree(tmp2);
|
||||
zfree(seed);
|
||||
seed = tmp;
|
||||
}
|
||||
|
||||
/*
|
||||
* libcalc shutdown
|
||||
*/
|
||||
libcalc_call_me_last();
|
||||
|
||||
/*
|
||||
* all done
|
||||
*/
|
||||
exit(0);
|
||||
}
|
125
sample/test_random.c
Normal file
125
sample/test_random.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* test_random - test the libcalc random number generator
|
||||
*
|
||||
* usage:
|
||||
* test_random [[bits] seed_string]
|
||||
*
|
||||
* seed_string something for which we can seed (def: default seed)
|
||||
* bits number of bits to generate
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 by Landon Curt Noll. All Rights Reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
* provided that the above copyright, this permission notice and text
|
||||
* this comment, and the disclaimer below appear in all of the following:
|
||||
*
|
||||
* supporting documentation
|
||||
* source copies
|
||||
* source works derived from this source
|
||||
* binaries derived from this source or from derived source
|
||||
*
|
||||
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
||||
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* chongo was here /\../\
|
||||
*/
|
||||
|
||||
|
||||
#if defined(__sgi)
|
||||
# include "../longbits.h"
|
||||
# if defined(HAVE_B64)
|
||||
typedef USB64 k_sigset_t;
|
||||
# else
|
||||
typedef struct {
|
||||
USB32 sigbits[2];
|
||||
} k_sigset_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include "../calc.h"
|
||||
#include "../zrandom.h"
|
||||
#include "../have_const.h"
|
||||
#include "../lib_util.h"
|
||||
|
||||
#define DEF_CNT 128 /* default number of bits to generate */
|
||||
|
||||
extern char *program; /* our name */
|
||||
|
||||
|
||||
MAIN
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
RANDOM *prev_state; /* previous random number state */
|
||||
ZVALUE seed; /* seed for Blum-Blum-Shub */
|
||||
ZVALUE random_val; /* random number produced */
|
||||
long cnt; /* number of bits to generate */
|
||||
char *hexstr; /* random number as hex string */
|
||||
|
||||
/*
|
||||
* parse args
|
||||
*/
|
||||
program = argv[0];
|
||||
switch (argc) {
|
||||
case 3:
|
||||
seed = convstr2z(argv[2]);
|
||||
cnt = strtol(argv[1], NULL, 0);
|
||||
break;
|
||||
case 2:
|
||||
seed = _zero_; /* use the default seed */
|
||||
cnt = strtol(argv[1], NULL, 0);
|
||||
break;
|
||||
case 1:
|
||||
seed = _zero_; /* use the default seed */
|
||||
cnt = DEF_CNT;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "usage: %s [[bits] seed_string]\n", program);
|
||||
exit(1);
|
||||
}
|
||||
if (cnt <= 0) {
|
||||
fprintf(stderr, "%s: cnt:%d must be > 0\n", program, (int)cnt);
|
||||
exit(2);
|
||||
}
|
||||
printf("seed= 0x%s\n", convz2hex(seed));
|
||||
|
||||
/*
|
||||
* libcalc setup
|
||||
*/
|
||||
libcalc_call_me_first();
|
||||
|
||||
/*
|
||||
* seed the generator
|
||||
*/
|
||||
prev_state = zsrandom2(seed, zconst[10]);
|
||||
if (prev_state == NULL) {
|
||||
math_error("previous random state is NULL");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/*
|
||||
* generate random bits
|
||||
*/
|
||||
zrandom(cnt, &random_val);
|
||||
|
||||
/*
|
||||
* convert into hex string
|
||||
*/
|
||||
hexstr = convz2hex(random_val);
|
||||
printf("random= 0x%s\n", hexstr);
|
||||
|
||||
/*
|
||||
* all done
|
||||
*/
|
||||
exit(0);
|
||||
}
|
Reference in New Issue
Block a user