The ncgfunc type is used to setup callbacks from the server to the client.
A callback registration function uses ncgfunc where it expects the callback
function pointer. A callback registration function must also have at
least one "void *" argument that will also be passed to the callback
function.
The prototype for the func arg of the callback registration function is
obtained from an "extern ncgfunc" declaration of the callback function
name. All callbacks return an int indicating whether to continue or
cancel the process that called it. Zero means cancel, non-zero means
continue.
Example:
/* globals to remember callback in */
int (*g_callback)(void *usr,SRCH *sr,ncgstr url);
void *g_usrdata;
%%
/* provide prototype for "ncgfunc cb" arg of reghitcb() */
extern ncgfunc cb(void *usr,SRCH *sr,ncgstr hit);
int reghitcb(void *usr,ncgfunc cb)
{
g_usrdata=usr;
g_callback=cb;
}
int search(SRCH *sr)
{
...
while(moretosearch)
if(hitfound)
if(!(*g_callback)(g_usrdata,sr,hit))
break;
...
}
%%
int mycallback(void *mystuff,SRCH *sr,char *hit)
{
...
puts(hit);
...
}
main()
{
SERVER *se;
SRCH *sr;
void *mystuff;
...
n_reghitcb(se,mystuff,mycallback);
n_search(se,sr);
...
}