4.9 Skipping Objects in the List: Example
/* itrskip.c
Example of NDS 8 Iterator NWDSItrSkip function
.
*/
#include <stdio.h>
#include <stdlib.h>
#include <nwnet.h>
#include <nwcalls.h>
void main(int argc, char *argv[])
{
NWDSContextHandle context =
(NWDSContextHandle)ERR_CONTEXT_CREATION;
nstr8 strAbbreviatedName[MAX_DN_CHARS+1];
NWDSCCODE ccode;
nuint32 flags;
nuint32 iter=0;
nint32 iterHandle = -1;
nuint32 timeout = 0; /* Timeout=0 means no time limit. */
nint32 numToSkip = 1;
nint32 actual;
/* Check arguments */
if(argc < 2)
{
printf("\nUsage: itrskip <base object> <+/-skip count>\n");
printf("\nExample: itrskip myou.myorg -100\n");
exit(1);
}
if (argc >= 3)
sscanf(argv[2], "%d", &numToSkip);
/* Initialize NWCalls and unicode tables */
ccode = NWCallsInit(NULL,NULL);
if(ccode) exit(1);
/* Create NDS Context */
ccode = NWDSCreateContextHandle(&context);
if(ccode) exit(1);
/* Set flags to get object names in typeless format. */
NWDSGetContext(context, DCK_FLAGS, &flags);
flags |= DCV_TYPELESS_NAMES;
NWDSSetContext(context, DCK_FLAGS, &flags);
printf("itrskip: Sample program for NWDSItrCount\n");
printf("Container: %s\n", argv[1]);
printf("Number of objects to skip: %d\n\n", numToSkip);
/* Convert the directory name (passed in as first arg) to its
shortest form relative to the name context */
ccode = NWDSAbbreviateName(context, argv[1], strAbbreviatedName);
if(ccode) goto error;
/* ———— Create the Iterator ————- */
ccode = NWDSItrCreateList(
context, /* context for this search */
strAbbreviatedName, /* container to search */
NULL, /* class name filter */
NULL, /* subordinate name filter */
DS_ITR_ANY_SERVER, /* scalability requirement */
timeout, /* 0 = no timeout */
&iter); /* returned Iterator ptr */
if (ccode)
goto error;
printf("Skipping %d objects...\n", numToSkip);
ccode = NWDSItrSkip(iter, numToSkip, timeout, &actual);
if (ccode == 0)
printf("Actual number of objects skipped = %d\n", actual);
else if (ccode == ERR_EOF_HIT)
printf("You tried to skip forward when Iterator was already
at EOF.\n");
else if (ccode == ERR_BOF_HIT)
printf("You tried to skip backward when Iterator was already
at top.\n");
/* Clean up, normal or error termination. */
error:
printf("\n\nccode = %d.",ccode);
if (iter)
NWDSItrDestroy(iter); /* Destroy the Iterator when done. */
NWDSFreeContext(context);
}