1. glutinit() and main() in C

void glutInit(int *argcp, char **argv);

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
}

Simple really blink
In main() :
int argc is  an int, usually equivalant to a euphoria integer. When the
program is run it's value is the number of command line arguments passed to
the program plus one.
eg prog 1 2 3 would set argc to 4, as the first one is the full program name
and path.

char **argv is a pointer to a pointer to a char. Which is sort of like an
array of arrays of chars but not quite. argv points to an array of pointers
to ascii strings. Think of it as an array of strings.

In glutinit() :
int *argcp is a pointer to an integer.

char **argv is the same as in main().

In the call glutInit(&argc, argv) :
&argc returns the address of an int. See argc is an int, argcp in glutinit()
is a pointer to an int. Pointers to ints contain adrresses of ints. So this
call gets the address of argc and passes it to glutinit().

argv is just passed by value.

How to translate to Euphoria.
sequence cmd
integer len

cmd = command_line()
cmd = {cmd[1]} & cmd[2..length(cmd)] -- Get rid of second element.
len = length(cmd)
Allocate an array of addresses len long.
Allocate an array for each element in cmd and poke it into memmory, put it's
addresses into the array created earlier.
Allocate an C_INT put len in it.
Pass it's address and the arrays address to glutinit()

Sorry I can't be more specific I have to go.

n.b. element 2 of command_line() doesn't exist in C.

--------------------
Sincerely,
Mathew Hounsell

Mat.Hounsell at Excite.Com




_______________________________________________________
Get your free, private email at http://mail.excite.com/

new topic     » topic index » view message » categorize

2. Re: glutinit() and main() in C

Mathew Hounsell wrote:
> void glutInit(int *argcp, char **argv);
> =A0
> int main(int argc, char** argv)
> {
>    glutInit(&argc, argv);
> }
> =A0
> Simple really blink
> In main() :
> int argc is  an int, usually equivalant to a euphoria integer. When t=
he
> program is run it's value is the number of command line arguments pas=
sed to
> the program plus one.
> eg prog 1 2 3 would set argc to 4, as the first one is the full progr=
am name
> and path.
> =A0
> char **argv is a pointer to a pointer to a char. Which is sort of lik=
e an
> array of arrays of chars but not quite. argv points to an array of po=
inters
> to ascii strings. Think of it as an array of strings.
> =A0
> In glutinit() :
> int *argcp is a pointer to an integer.
> =A0
> char **argv is the same as in main().
> =A0
> In the call glutInit(&argc, argv) :
> &argc returns the address of an int. See argc is an int, argcp in glu=
tinit()
> is a pointer to an int. Pointers to ints contain adrresses of ints. S=
o this
> call gets the address of argc and passes it to glutinit().
> =A0
> argv is just passed by value.
> =A0
> How to translate to Euphoria.
> sequence cmd
> integer len
> =A0
> cmd =3D command_line()
> cmd =3D {cmd[1]} & cmd[2..length(cmd)] -- Get rid of second element.

Should be: cmd =3D {cmd[1]} & cmd[3..length(cmd)]
As you can read on the last line of this mail!

> len =3D length(cmd)
> Allocate an array of addresses len long.
> Allocate an array for each element in cmd and poke it into memmory, p=
ut it's
> addresses into the array created earlier.
> Allocate an C_INT put len in it.
> Pass it's address and the arrays address to glutinit()
> =A0
> Sorry I can't be more specific I have to go.
> =A0
> n.b. element 2 of command_line() doesn't exist in C.
> =A0
> --------------------
> Sincerely,
> Mathew Hounsell
> =A0
> Mat.Hounsell at Excite.Com
> =A0
> =A0
> =A0
> =A0
> _______________________________________________________
> Get your free, private email at http://mail.excite.com/
>



 | Gratis e-mail en meer: http://www.dolfijn.nl/
 | Een product van Ilse: http://www.ilse.nl/

new topic     » goto parent     » topic index » view message » categorize

3. Re: glutinit() and main() in C

Hello again,

>How to translate to Euphoria.
>sequence cmd
>integer len
>
>cmd =3D command_line()
>cmd =3D {cmd[1]} & cmd[2..length(cmd)] -- Get rid of second element.
>len =3D length(cmd)
>Allocate an array of addresses len long.
>Allocate an array for each element in cmd and poke it into memmory, put=
 it's
>addresses into the array created earlier.
>Allocate an C_INT put len in it.
>Pass it's address and the arrays address to glutinit()

Here's what I came up with:

=A6atom array_ad, array_len
=A6sequence free_stuff
=A6free_stuff =3D {}
=A6-------------------------------------------------------------------------=
---
=A6procedure handle_command_line()
=A6atom string
=A6integer len
=A6sequence cmd
=A6cmd =3D command_line()
=A6cmd =3D cmd[2..length(cmd)] -- actually wants the name of the program
=A6len =3D length(cmd)
=A6array_ad =3D allocate (len*4)
=A6free_stuff=3D append(free_stuff,array_ad) -- so I free it later
=A6for i =3D 1 to len do
=A6    string =3D allocate_string(cmd[i] & 0) -- add 0 to denote end of=
 string
=A6    free_stuff =3D append(free_stuff,string)
=A6    poke (string,cmd[i] & 0)
=A6    poke (array_ad+((len-1)*4), int_to_bytes(string))
=A6end for
=A6array_len =3D allocate(4)
=A6free_stuff =3D append(free_stuff,array_len)
=A6poke (array_len, int_to_bytes(len))
=A6end procedure
=A6-------------------------------------------------------------------------=
---
=A6handle_command_line()
=A6-------------------------------------------------------------------------=
---

Well, heh it still does not appear to work. Although GLUT did try to open a
window
but soon bombed after that. Did I miss something? Or is the problem else
where?

Thank you guys for all of your help so far.  =20

new topic     » goto parent     » topic index » view message » categorize

4. Re: glutinit() and main() in C

>=A6    poke (array_ad+((len-1)*4), int_to_bytes(string))
Sorry this should of been
>=A6    poke (array_ad+((i-1)*4), int_to_bytes(string))

Still have problem!

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu