So I was the last one :)

My example is using python interpreter -- it's maybe simpler to use in
many cases, but theoretically slower.

It is, anyway, not so advanced to import portage, but you can add that line ;)

2006/3/15, solar <[EMAIL PROTECTED]>:
> On Wed, 2006-03-15 at 21:42 +0100, Kevin F. Quinn (Gentoo) wrote:
> > On Wed, 15 Mar 2006 09:52:13 -0500
> > solar <[EMAIL PROTECTED]> wrote:
> >
> > > On Wed, 2006-03-15 at 10:51 +0100, Paul de Vrieze wrote:
> > >
> > > [snip]
> > >
> > > > Actually, C++ being strongly related to C, can just use the C
> > > > python api's. As such it could directly interface with python, and
> > > > use the python portage api.
> > >
> > > If you could demonstrate an 'import portage' and a simple
> > > printf("PORTDIR=%s\n", PORTDIR); in C I'd be highly interested.
> >
> > Try attached :)  Had a go 'coz I was curious.  Compile with:
> >
> > gcc -o getportdir getportdir.c -lpython2.4
> >
> > Does the equivalent of:
> >
> > #!/usr/bin/portage
> > import portage;
> > print portage.settings["PORTDIR"];
> >
> > (more or less).  Docs on the API itself (which comes with Python) are at
> > http://docs.python.org/api/api.html
>
> thanks Kevin,
>  marienz also put 3 examples together to demonstrate it.
>
> /me feels like a kid in a candy store.
>
> thanks guys.
>
>
> --
> solar <[EMAIL PROTECTED]>
> Gentoo Linux
>
> --
> gentoo-portage-dev@gentoo.org mailing list
>
>


--
tvali
(e-mail: "[EMAIL PROTECTED]"; msn: "[EMAIL PROTECTED]";
icq: "317-492-912")

Ühe eesti internetifirma lehel kohtasin tsitaati:
If you don't do it excellently, dont do it at all. Because if it's not
excellent, it won't be profitable or fun, and if you're not in
business for fun or profit, what the hell are you doing here?
Robert Townsend
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <wait.h>

void python(int input[2], int output[2]) {
        dup2(output[1], STDOUT_FILENO);
        dup2(input[0], STDIN_FILENO);
        close(output[0]);
        close(output[1]);
        close(input[0]);
        close(input[1]);
        char *const args[] = { "/usr/bin/python", NULL };
        execv(args[0], args);
        _exit(EXIT_FAILURE);
}

int main(int argc, char *argv[])
{
    int input[2];
    pipe(input);
    int output[2];
    pipe(output);

    if (fork() == 0) python(input, output);

    FILE *inputf, *outputf;

    close(output[1]);
    close(input[0]);
    outputf = fdopen(output[0], "r");
    inputf = fdopen(input[1], "w");

    fputs("print 123\n", inputf);
    fclose(inputf);

    char tt;
    for (tt=0; tt<40; tt++)
      fputc(tt, inputf);

    int c;
    while ((c = fgetc(outputf)) != EOF)
	  fputc(c, stdout);

    fputc(EOF, inputf);

    wait(NULL);
    return 0;
}



Reply via email to