Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Running a program (gperf) inside another C program

Reply
Thread Tools

Running a program (gperf) inside another C program

 
 
Alexander Mahone
Guest
Posts: n/a
 
      05-26-2008
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
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      05-26-2008
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.
--
Flash Gordon
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      05-26-2008
In article <(E-Mail Removed)>,
Alexander Mahone <(E-Mail Removed)> wrote:
>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.

--
"It's a hard life sometimes and the biggest temptation is to let
how hard it is be an excuse to weaken." -- Walter Dean Myers
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-26-2008
Flash Gordon <(E-Mail Removed)> writes:
[...]
> 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?

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      05-26-2008
Keith Thompson wrote, On 26/05/08 19:33:
> Flash Gordon <(E-Mail Removed)> writes:
> [...]
>> 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?


Yes, thank you.
--
Flash Gordon
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a program from another program. Laurent Verweijen Python 0 06-17-2010 07:13 PM
running another program from a C++ program Lorenzo Bettini C++ 3 09-24-2005 10:05 AM
Help !I want to write a program to count the running time of another program freehomesp@yahoo.com.cn C Programming 1 08-12-2005 06:13 AM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
PN: Sample code to call another program/command from inside a C++ program Peter Nolan C++ 4 04-08-2004 08:33 PM



Advertisments