Special Types: ncgbuffer

The special type "ncgbuffer" is used to specify an arbitrary chunk of data to be transferred between client and server. It becomes "TSPBUFFER *" in the generated code. A TSPBUFFER has two members; buf is a pointer to the data and n is the count of bytes pointed to. The buf member is allocated for each transfer and must be freed when no longer needed.

Example:

...
%%
void firstword(ncgbuffer b)    /* return the first word in the buffer */
{
 int i;

 for(i=0;i<b.n && b.buf[i]!=' ';i++);             /* search for space */
 b.n=i;                   /* reset length of buffer to what was found */
}
%%
main()
{
 SERVER *se;
 TSPBUFFER b;
 int i;

 ...

    b.buf="Expansion Programs"; /* setup buffer to send to the server */
    b.n=strlen(b.buf);
    n_firstword(se,&b);    /* call server to get first word in buffer */
    for(i=0;i<b.n;i++) putchar(b.buf[i]);  /* print the result buffer */
    putchar('\n');
    free(b.buf);                          /* free the returned buffer */
 ...
}

Would print:

Expansion


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.