cfunc.select C Function/C Functions

cfunc.select

Command cfunc.select C Function/C Functions
Applicable release versions: AP 6.1
Category C Functions (120)
Description equivalent to the following Pick/BASIC statement: select expression1 to list

If expression2 is non-zero, then the "secondary" list is assumed.

The default behavior of _CP_select is to create an internal select list which contains the item-id's of the file pointed to by expression1. Expression1 must have been previously created by a _CP_open call.

Note however, that, as in Pick/BASIC, if an external select list is present (i.e. one created by a previous call to _CP_execute), that the value of expression1 will be ignored. In this case, the user may pass -1 for expression1 if desired.

This function returns -1 if an error occurs. The error code is contained in _CP_errno.

The user C program should always process all of the items in the list or call _CP_clearselect to dispose of the list prematurely. Failure to do this may cause unreasonable memory or overflow usage.
Syntax int _CP_select(int expression1, int* list, int expression2)
Options
Example
The following example prints the item names in "myfile".

CPSTR * n = _CP_mkstr("myfile");
CPSTR * id = _CP_str_null;
int sl = -1;
int f = -1;

_CP_open(&f, _CP_str_null, n);
_CP_select(f, &sl, 0);
while (_CP_readnext(&id,&sl,(int*)0,0)>=0)
  _CP_print(id);

The following example demonstrates how an external select list will override 
the file variable passed as expression1.  Here, "myfile" is passed to 
the select, but the readnext will return items from the "md".

CPSTR * n = _CP_mkstr("myfile");
CPSTR * s = _CP_mkstr("select md sampling 3");
CPSTR * id = _CP_str_null;
int sl = -1;
int f = -1;

_CP_execute(_CP_EXECUTE, s, (CPSTR**) 0, (CPSTR**) 0);
_CP_open(&f, _CP_str_null, n);
_CP_select(f, &sl, 0);
while (_CP_readnext(&id, &sl, (int*) 0, 0) >= 0)
  _CP_print(id);
Purpose
Related cfunc.introduction
cfunc.clearselect