4.5 Getting Iterator Information: Example

  /* itrinfo.c 
     Example of NDS 8 Iterator informational functions: 
        NWDSItrGetInfo 
        NWDSItrAtFirst 
        NWDSItrAtEOF 
  */ 
   
  #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; 
     nuint32      timeout = 0;     /* Timeout=0 means no time limit. */ 
     nbool8       isScalable; 
     nbool8       isPositionable; 
   
  /* Check arguments */ 
     if(argc < 2) 
     { 
        printf("\nUsage:    itrinfo  <base object>\n"); 
        printf("\nExample:  itrinfo  myou.myorg\n"); 
        exit(1); 
     } 
   
     /* 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("itrinfo:   Sample program for Iterator informational
             functions.\n"); 
     printf("Container:    %s\n", argv[1]); 
   
     /* 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; 
   
   
     ccode = NWDSItrGetInfo(iter, &isScalable, &isPositionable); 
     if (ccode) goto error; 
   
     if (isScalable) 
        printf("  This Iterator is SCALABLE.\n"); 
     else 
        printf("  This Iterator is NOT SCALABLE.\n"); 
   
     if (isPositionable) 
        printf("  This Iterator is POSITIONABLE.\n"); 
     else 
        printf("  This Iterator is NOT POSITIONABLE.\n"); 
   
     if (NWDSItrAtFirst(iter)) 
        printf("  Iterator is positioned at first entry.\n"); 
   
     if (NWDSItrAtEOF(iter)) 
        printf("  Iterator is positioned at EOF, or is empty.\n"); 
   
   
  /* Clean up, normal or error termination. */ 
  error: 
     printf("\n\nccode = %d.",ccode); 
     if (iter) 
        NWDSItrDestroy(iter);      /* Destroy the Iterator when done. */ 
     NWDSFreeContext(context); 
  }