I already tried typing this twice but this New Thread page had expired and I didn't learn my lesson the first time. The problem is kinda huge, so I'll try to mention everything but probably won't.
My program has 3 layers: the bash wrapper, the makefile, and the source. The wrapper will be discarded for deployment. I'm not totally sure which one contains the bug; I think it's in the source because the other 2 are pretty big, but I already scoured it. I provide CLI.Makefile below; GUI.Makefile is basically the same.
The bug manifests as unresponsiveness. C prompts me for some input, but then allows me to keep typing as much as I want - even newlines. After that it just stops without even exiting; when I close the terminal, the wrapper redirects Valgrind's output, which complains of still-reachable blocks from gtk_init. This happens regardless of whether I ask for the CLI or GUI.
If you would like, I can post a short version of Valgrind's output.
I'm sorry to post bash code here, but I don't see a better alternative...
Code:
#!/bin/bash
face="CLI";
comm="valgrind";
if [ "$1" != "" ]; then
if [ "$1" == "GUI" ] || [ "$1" == "CLI" ]; then
face="$1";
else
echo "Invalid argument; should be either \"CLI\" or \"GUI\".";
exit;
fi
fi
function compile(){
make -f "$face.Makefile"
echo;
}
function mingw(){
make;
echo;
}
function gnu(){
compile;
gdb ./outliner -q;
prompt;
}
function val(){
compile;
valgrind --show-reachable=yes --leak-check=full --suppressions=Outliner.supp ./outliner --gen-suppressions=yes &> ./output;
prompt;
}
function run(){
compile;
./outliner;
prompt;
}
function prompt(){
local new="";
local valid=1;
echo;
read -p "Enter a command [quit / gdb / valgrind / run] (default: $comm): " new;
if [ "$new" = "quit" ]; then
exit;
fi
if [ "$new" = "" ]; then
new="$comm"
valid=$(( $valid & ~1 )); # Flip the first bit off.
fi
if [ "$new" = "gdb" ]; then
valid=$(( $valid | 2 )); # Flip the second bit on.
fi
if [ "$new" = "valgrind" ]; then
valid=$(( $valid | 4 )); # Flip the third bit on.
fi
if [ "$new" = "run" ]; then
valid=$(( $valid | 8 )); # Flip the fourth bit on.
fi
if [ $(( $valid & 14 )) != 0 ]; then # Is the command valid?
if [ $(( $valid & 1 )) != 0 ]; then # Was it entered at this prompt?
comm="$new";
fi
else
if [ $(( $valid & 1 )) == 0 ]; then
echo "Error: Invalid command.";
prompt;
return;
fi
fi
if [ $(( $valid & 2 )) != 0 ]; then
gnu;
fi
if [ $(( $valid & 4)) != 0 ]; then
val;
fi
if [ $(( $valid & 8)) != 0 ]; then
run;
fi
}
cd ~/NetBeansProjects/Outliner;
prompt;
exit;
CLI.Makefile
Code:
# Makefile
CC = gcc
CFLAGS = -ggdb -ansi -lm
OBJECTS = main.o interface.o outline.o ../Jesdisciple/filesystem.o ../Jesdisciple/list.o ../Jesdisciple/toolkit.o
outliner: $(OBJECTS)
$(CC) `pkg-config --cflags --libs gtk+-2.0` -o $@ $^ $(CFLAGS) -D INTERFACE=0
main.o: main.c interface.h
interface.o: interface.c interface.h
interface.h: outline.h
outline.o: outline.c outline.h
outline.h: ../Jesdisciple/filesystem.h
include ../Jesdisciple/Makefile
main.c
Code:
/*
* File: main.c
* Author: Jesdisciple
*
* Created on December 23, 2008, 3:00 PM
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "../Jesdisciple/toolkit.h"
#include "outline.h"
#include "interface.h"
#include <stdlib.h>
int main(int argc, char **argv){
#if INTERFACE == GRAPHICAL
gtk_init(&argc, &argv);
#endif
struct outline_interface face = {
(struct outline *)NULL,
die,
error,
alert,
prompt,
menu,
confirm,
help,
start,
make,
graft,
show,
open,
save,
load,
(void (*)(struct outline_interface *))NULL
};
outline_init(&face);
#if INTERFACE == GRAPHICAL
gtk_main();
#endif
free(outline_home);
return 0;
}
#ifdef __cplusplus
}
#endif
Thanks!!!