Re: [gtk-list] Re: Need help in GTK-project
- From: Bart Vandewoestyne <Bart Vandewoestyne skynet be>
- To: gtk-list redhat com, gtk-app-dev-list redhat com
- Subject: Re: [gtk-list] Re: Need help in GTK-project
- Date: Thu, 09 Dec 1999 21:46:45 +0100
Erik Mouw wrote:
>
> On Sun, 05 Dec 1999 02:47:26 +0100, Bart Vandewoestyne wrote:
> > I'm trying to write a GTK-application to drive a stepper motor using the
> > parallel port. I do have a little bit of problems with my program. I'm
> > quite new at GTK. People who want to take a look at my program and can
> > give me some constructive hints about it can find the program on
> > http://hello.to/MC303 -> just follow the link to "Stepper Motor" on the
> > left of the screen. I would recommend checking out the buggy version...
> > I appreciate feedback on my program, program-style, Makefile, and of
> > course on the many bugs that my program still contains... I want to
> > learn myself good programming style and will need some expert-feedback
> > on this. Getting some feedback from the pro's would be a great help to
> > learn about GTK programming I think...
>
> >From motor.c:
> * To be able to run as user do as root:
> * # chown root ~user/place_to_be/motor
> * # chmod ug+s ~user/place_to_be/motor
>
> GTK is _not_ considered safe enough to be useful for root or suid root
> programs. Make a small helper application that can safely be suid'ed, it
> only has to do the ioperm() and outb() plus it needs some way to
> communicate with the main program (which does the user interface).
What do you mean by 'helper application'? I don't have much experience
in this... can you be a little bit more specific ?
> I'd suggest using more header files, so
> showmessage.c gets a header file showmessage.h.
Why do I need a headerfile for this? Sorry to ask such stupid
questions, but this is my first BIG program... at school al always
learned to program in just one .c file and that was quite stupid I
think... I never actually learned to work well with headerfiles. Can
you give me some tips on using more headerfiles for my program? When
should I decide to make a headerfile and what kind of stuff should
belong in that headerfile ?
> Oh, and please do use the
> anti-double-include-header-file trick (this example is for motor.h):
>
> #ifndef MOTOR_MOTOR_H
> #define MOTOR_MOTOR_H
>
> /* asm/io.h is not needed here, but in motor.c, so include it there
> * same for unistd.h and stdio.h. gtk.h needs to be included here
> */
>
> #include <gtk/gtk.h>
>
> ... rest of motor.h ...
>
> #endif
OK, I think I've changed everything like you told me to... still, i get
these two errors when I compile my program:
main.c: In function `main':
main.c:19: warning: implicit declaration of function `ioperm'
main.c:19: warning: implicit declaration of function `perror'
any suggestions ?
> Oh, "int portstatus" doesn't belong in a header file, but in one of the C
> files.
I have put portstatus as a global variabele in main.c, is this ok?
Could you also please explain me why it is better to put it in a .c file
instead of in a .h file ?
> Another thing: avoid namespace pollution. Your project is small enough to
> be bitten by it, but you actually should prefix all your functions and
> variables (so mot_CreateMenuItem() and MOT_LEFT). Been there and learned
> it the hard way.
Huh? Need more explanation on this...
> About your Makefile, try my version which uses implicit rules etc. It's
> not as sophisticated as a version that fully supports GNU make, but it
> will work with most sane make utilities.
First of all: can you explain what 'implicit rules' are ?
> # The main things: compiler, linker, flags
> CC=gcc
> CFLAGS=-Wall -O2 -g `gtk-config --cflags`
> LDFLAGS=-g
> LIBS=`gtk-config --libs`
>
> # Sources, object files and target
> SRCS=main.c motor.c menu.c misc.c about.c showmessage.c
> OBJS=main.o motor.o menu.o misc.o about.o showmessage.o
> TARGET=motor
>
> # Implicit rules
> .c.o:
> $(CC) $(CFLAGS) -c $< -o $@
I don't quite understand the last 3 lines... Somebody who wants to
explain them to me ?
> # Some phony targets (i.e. targets without files)
> .PHONY: all clean realclean install
'phony targets' ???
> all: $(TARGET)
>
> $(TARGET): $(OBJS)
> $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
What is this $@ thing doing in between ???
> clean:
> rm -f $(OBJS) $(TARGET)
>
> realclean: clean
> rm -f *~
>
> install: $(TARGET)
> chown root.mc303 $(TARGET)
> chmod ug+s $(TARGET)
Tnx! The Makefile did very well!
> HTH
It sure did help! Programming practice is the best way to learn :-)
People who want to give me more feedback, tips, bug reports etc... on my
program should take a look at http://hello.to/MC303 and follow the link
'stepper motor' on the left and download the buggy version. I updated
it today. The program has already been expanded and I have changed the
things you adviced me to change. Want to check it out and send me
feedback ?
> Erik
Greetzzz
MC303
--
Bart Vandewoestyne http://hello.to/MC303
Hugo Verrieststraat 48 Bart.Vandewoestyne@skynet.be
8550 ZWEVEGEM ICQ# 21275340
BELGIUM - EUROPE nick: MC303
Phone: +32(0)56/75.48.11
-------------------------------------------------------------------
If carpenters made buildings the way programmers make programs, the
first woodpecker to come along would destroy all of civilization.
- Weinberg's Second Law -
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]