Example A-3. The long_seln.c program (continued)
{
char *text = get_selection();
if (text)
printf("seln\n%.*s [...]\nend seln\n", 20, text);
}
/*
* return the text selected in the current selection rank. Use
* selection_query() to guarantee that the entire selection is
* retrieved. selection_query() calls our installed routine,
* read_proc() (see below).
*/
char *
get_selection()
{
Seln_holder holder;
Seln_result result;
Seln_request *response;
char context = FIRST_BUFFER;
holder = selection_inquire(server, seln_type);
printf("selection type = %s\n",
seln_type == SELN_PRIMARY? "primary" :
seln_type == SELN_SECONDARY? "secondary" : "shelf");
/* result is based on the return value of read_proc() */
result = selection_query(server, &holder, read_proc, &context,
SELN_REQ_BYTESIZE, NULL,
SELN_REQ_CONTENTS_ASCII, NULL,
NULL);
if (result == SELN_FAILED) {
puts("couldn’t get selection");
return NULL;
}
return seln_bufs[seln_type ];
}
/*
* Called by selection_query for every buffer of information received.
* Short messages (under about 2000 bytes) will fit into one buffer.
* For larger messages, read_proc is called for each buffer in the
* selection. The context pointer passed to selection_query is
* modified by read_proc so that we know if this is the first buffer
* or not.
*/
Seln_result
read_proc(response)
Seln_request *response;
{
char *reply; /* pointer to the data in the response received */
long seln_len; /* total number of bytes in the selection */
static long seln_have_bytes;
/* number of bytes of the selection
* which have been read; cumulative over all calls for
650 XView Programming Manual
Example A-3. The long_seln.c program (continued)
* the same selection (it is reset when the first
* response of a selection is read)
*/
printf("read_proc status: %s (%d)\n",
response->status == SELN_FAILED? "failed" :
response->status == SELN_SUCCESS? "succeeded" :
response->status == SELN_CONTINUED? "continued" : "???",
response->status);
if (*response->requester.context == FIRST_BUFFER) {
reply = response->data;
/* read in the length of the selection -- first attribute.
* advance "reply" passed attribute to point to actual data.
*/
reply += sizeof(SELN_REQ_BYTESIZE);
/* set seln_len to actual data now. (bytes selected) */
seln_len = *(int *)reply;
printf("selection size is %ld bytes\n", seln_len);
/* advance "reply" to next attribute in list */
reply += sizeof(long);
/* create a buffer large enough to store entire selection */
if (seln_bufs[seln_type] != NULL)
free(seln_bufs[seln_type ]);
if (!(seln_bufs[seln_type] = malloc(seln_len + 1))) {
puts("out of memory");
return(SELN_FAILED);
}
seln_have_bytes = 0;
/* move "reply" passed attribute so it points to contents */
reply += sizeof(SELN_REQ_CONTENTS_ASCII);
*response->requester.context = NOT_FIRST_BUFFER;
} else {
/* this is not the first buffer, so the contents of the
* response is just more of the selection
*/
reply = response->data;
}
/* copy data from received to the seln buffer allocated above */
(void) strcpy(&seln_bufs[seln_type ][seln_have_bytes], reply);
seln_have_bytes += strlen(reply);
return SELN_SUCCESS;
}
The Selection
Service
The Selection Service 651
A.5 Selection Package Summary
Table A-2 lists the procedures and macros in the Selection Service. Table A-3 lists the
Selection Service Attributes.
Table A-2. Selection Service Procedures
Selection Procedures
selection_acquire() selection_inform()
selection_ask() selection_init_request()
selection_clear_functions() selection_inquire()
selection_create() selection_inquire_all()
selection_destroy() selection_query()
selection_done() selection_report_event()
selection_figure_response() selection_request()
selection_hold_file() selection_yield_all()
Table A-3. Selection Service Attributes
Selection Attributes Advanced Selection Attributes
SELN_REQ_BYTESIZE SELN_REQ_COMMIT_PENDING_DELETE
SELN_REQ_CONTENTS_ASCII SELN_REQ_CONTENTS_PIECES
SELN_REQ_DELETE SELN_REQ_FAKE_LEVEL
SELN_REQ_END_REQUEST SELN_REQ_FIRST
SELN_REQ_FILE_NAME SELN_REQ_FIRST_UNIT
SELN_REQ_YIELD SELN_REQ_LAST
SELN_REQ_LAST_UNIT
SELN_REQ_LEVEL
SELN_REQ_RESTORE
SELN_REQ_SET_LEVEL
652 XView Programming Manual
This page intentionally left blank
to preserve original page counts.
This page intentionally left blank
to preserve original page counts.

Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.