modelling.data@gmail.com writes:
Hello!
I have written a post regarding the same program.
You should provide a makefile along with your program! Otherwise, how
can we know how to compile it, what options you used, and how to run it?
Here is the makefile I used, but if yours is different, then obviously
we will have different results, and I won't be able to debug your
program.
I have an issue with the easiest part of it, and I don't see
my mistake: the for loop in the BRICKS FUNCTION doesn't create
5 rows of bricks, but only 2, albeit the amount of columns is correct
(all bricks are perfectly aligned within 10 columns). The program
prints out only 2 rows of bricks.
Indeed, it does. However, I remark that it exits and the window
displayed by the JavaBackEnd stays up.
Therefore I would infer that there's a bufferization problem: you have
to leave the connection open enough time for the data to be actually
sent and received by the JavaBackEnd. The unix kernel probably drops
the data that's in the pipe when the writer process is killed or exits.
One way to ensure that the JavaBackEnd has read everything you sent, is
to actually implement what would be normal in a GUI application: an
event loop. If you wait for a mouse-down event on the window, then you
will ensure that all you sent has been received.
Also, you have a bug in your initBricks(), you set y to a constant in
the loop. Therefore all the new bricks beyond the first two rows will be displayed on the second row.
[pjb@kuiper localhost:10.0 spl]$ make -f bricks.mk run-bricks
cc -g3 -O0 -std=c99 -std=c11 -o bricks.o -c bricks.c
cc -g3 -O0 -std=c99 -std=c11 -o bricks bricks.o -lcs -lm -lobjc CLASSPATH=/usr/local/lib/spl.jar ./bricks
C-c C-c
Interrupted: exiting.
bricks.mk:14: recipe for target 'run-bricks' failed
make: *** [run-bricks] Interrupt
[pjb@kuiper localhost:10.0 spl]$
Here are my files:
------------------------------------------------------------------------ #!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.14).
# To extract the files from this archive, save it to some FILE, remove
# everything before the '#!/bin/sh' line above, then type 'sh FILE'.
#
lock_dir=_sh18948
# Made on 2015-11-14 22:23 CET by <pjb@kuiper>.
# Source directory was '/home/pjb/src/miscellaneous/spl'.
#
# Existing files will *not* be overwritten, unless '-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 379 -rw-r--r-- bricks.mk
# 1527 -rw-r--r-- bricks.c
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
if test "X$1" = "X-c"
then keep_file=''
else keep_file=true
fi
echo=echo
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=
locale_dir=
set_echo=false
for dir in $PATH
do
if test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir
set_echo=true
break ;;
esac
fi
done
if ${set_echo}
then
set_echo=false
for dir in $PATH
do
if test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
set_echo=true
break
fi
done
if ${set_echo}
then
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
fi
IFS="$save_IFS"
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901
if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and
installing GNU '\''touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir} ; then :
else ${echo} "lock directory ${lock_dir} exists"
exit 1
fi
if mkdir ${lock_dir}
then ${echo} "x - created lock directory ${lock_dir}."
else ${echo} "x - failed to create lock directory ${lock_dir}."
exit 1
fi
# ============= bricks.mk ==============
if test -n "${keep_file}" && test -f 'bricks.mk'
then
${echo} "x - SKIPPING bricks.mk (file already exists)"
else
${echo} "x - extracting bricks.mk (text)"
sed 's/^X//' << 'SHAR_EOF' > 'bricks.mk' &&
all: bricks
X
LIBS=-lcs -lm -lobjc
CFLAGS=-g3 -O0 -std=c99 -std=c11
X
%.o:%.m;cc $(CFLAGS) -o $@ -c $^
%.o:%.c;cc $(CFLAGS) -o $@ -c $^
X
bricks.o:bricks.c
bricks:bricks.o
X cc $(CFLAGS) -o $@ $^ $(LIBS)
X
run-bricks:bricks
X CLASSPATH=/usr/local/lib/spl.jar ./bricks
X
debug-bricks:bricks
X JBETRACE=true CLASSPATH=/usr/local/lib/spl.jar ./bricks
X
clean:
X -rm -rf bricks *.dSYM *.o
X
SHAR_EOF
(set 20 15 11 14 22 22 21 'bricks.mk'
eval "${shar_touch}") && \
chmod 0644 'bricks.mk'
if test $? -ne 0
then ${echo} "restore of bricks.mk failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'bricks.mk': 'MD5 check failed'
) << \SHAR_EOF
08f3fc95e6ba9bb115154029c5351a2d bricks.mk
SHAR_EOF
else
test `LC_ALL=C wc -c < 'bricks.mk'` -ne 379 && \
${echo} "restoration warning: size of 'bricks.mk' is not 379"
fi
fi
# ============= bricks.c ==============
if test -n "${keep_file}" && test -f 'bricks.c'
then
${echo} "x - SKIPPING bricks.c (file already exists)"
else
${echo} "x - extracting bricks.c (text)"
sed 's/^X//' << 'SHAR_EOF' > 'bricks.c' &&
// standard libraries
#include <stdio.h>
#include <signal.h>
// Stanford Portable Library
#include <spl/gevents.h>
#include <spl/gobjects.h>
#include <spl/gwindow.h>
#include <spl/platform.h>
X
// height and width of game's window in pixels
#define HEIGHT 600
#define WIDTH 400
X
// number of rows of bricks
#define ROWS 5
X
// number of columns of bricks
#define COLS 10
X
// horizontal space between bricks
#define HS 10
#define VS 10
X
// brick size
#define BRWIDTH 29
#define BRHEIGHT 15
X
void initBricks(GWindow window);
X
bool done=false;
bool interrupted=false;
void sigint(int signal){
X interrupted=true;
X done=true;}
X
void eventLoop(){
X while(!done){
X GEvent e=getNextEvent(MOUSE_EVENT);
X if(e!=0){
X if(getEventType(e)==MOUSE_CLICKED){
X done=true;}
X freeEvent(e);}}}
X
int main(void)
{
X signal(SIGINT,sigint);
X signal(SIGQUIT,sigint);
X GWindow window = newGWindow(WIDTH, HEIGHT);
X initBricks(window);
X eventLoop();
X if(interrupted){
X printf("\nInterrupted: exiting.\n");
X fflush(stdout);}
X exitGraphicsOp();
X return 0;
}
X
/** BRICKS FUNCTION **/
void initBricks(GWindow window)
{
X GRect brick;
X double y = VS * 5;
X for (int i = 0; i < ROWS; i++)
X {
X double x = 10;
X y = y + BRHEIGHT + VS;
X for (int j = 0; j < COLS; j++)
X {
X brick = newGRect(x, y, BRWIDTH, BRHEIGHT);
X add(window, brick);
X
X x = x + BRWIDTH + HS;
X }
X
X }
}
SHAR_EOF
(set 20 15 11 14 22 16 45 'bricks.c'
eval "${shar_touch}") && \
chmod 0644 'bricks.c'
if test $? -ne 0
then ${echo} "restore of bricks.c failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'bricks.c': 'MD5 check failed'
) << \SHAR_EOF
2b8bed01642279076e0076c052d83adf bricks.c
SHAR_EOF
else
test `LC_ALL=C wc -c < 'bricks.c'` -ne 1527 && \
${echo} "restoration warning: size of 'bricks.c' is not 1527"
fi
fi
if rm -fr ${lock_dir}
then ${echo} "x - removed lock directory ${lock_dir}."
else ${echo} "x - failed to remove lock directory ${lock_dir}."
exit 1
fi
exit 0
------------------------------------------------------------------------
--
__Pascal Bourguignon__
http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)