Running a program (gperf) inside another C program

A

Alexander Mahone

Hello, apart from using fork() and exec*(), or system(), is there any
other way to run the gperf command line program inside a C program? I
need to generate at run-time a perfect hash function, and it seems
that gperf has no API to execute it programmatically, so the only way
is to call it as an external program, and instruct it to write the
ouput code to a certain file whose path I know.
Thanks a lot
 
F

Flash Gordon

Alexander Mahone wrote, On 26/05/08 14:41:
Hello, apart from using fork() and exec*(), or system(), is there any
other way to run the gperf command line program inside a C program? I

In standard C the only method is system(), anything else is system
specific, so I suggest asking in comp.unix.programmer.
need to generate at run-time a perfect hash function, and it seems
that gperf has no API to execute it programmatically, so the only way
is to call it as an external program, and instruct it to write the
ouput code to a certain file whose path I know.
Thanks a lot

A better method almost certainly is to either find or write a library
that does what you want. If you search the group you will find that
hashing has been discussed several times here. Alternatively a simple
google search for "perfect has library" without the quotes shows some
options.
 
W

Walter Roberson

Hello, apart from using fork() and exec*(), or system(), is there any
other way to run the gperf command line program inside a C program?

Note that C does not define fork() or exec*(), only system().
I
need to generate at run-time a perfect hash function, and it seems
that gperf has no API to execute it programmatically, so the only way
is to call it as an external program, and instruct it to write the
ouput code to a certain file whose path I know.

Which system() should do fine for.

Anything beyond system() is system-specific.

[OT]
Based upon your reference to fork() and exec*(), it looks like you
might be using a POSIX type system. If so, then -possibly-,
depending on your system architecture and how exactly gperf was
compiled, you -might- be able to use operating system facilities to
request that gperf be loaded -as if- it were a dynamic library,
find it's entry point, and dispatch to that. Common facility
names that might give this kind of access are dlopen() and dlsym().
You might or might not be able to find a symbol within the program
that gives you a callable API; if not, then you would still have
to create command line arguments, possibly use dup2() or similiar
OS facilities do feed the program with internal streams instead of
creating a real file...

On the other hand, the kinds of systems that tend to make hacks
like the above possible, usually have ways of "pre-linking"
programs: in such cases, the speed difference between the hack I
mentioned vs invocation via system() is probably close to unmeasurable.
 
K

Keith Thompson

Flash Gordon said:
A better method almost certainly is to either find or write a library
that does what you want. If you search the group you will find that
hashing has been discussed several times here. Alternatively a simple
google search for "perfect has library" without the quotes shows some
options.

You mean "perfect hash library", yes?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top