home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / srchdr.exe / SRCHDR.C next >
C/C++ Source or Header  |  1995-08-21  |  7KB  |  184 lines

  1. /****************************************************************************
  2. **      DISCLAIMER  
  3. **  
  4. **   Novell, Inc. makes no representations or warranties with respect to
  5. **   any NetWare software, and specifically disclaims any express or
  6. **   implied warranties of merchantability, title, or fitness for a
  7. **   particular purpose.  
  8. **
  9. **   Distribution of any NetWare software is forbidden without the
  10. **   express written consent of Novell, Inc.  Further, Novell reserves
  11. **   the right to discontinue distribution of any NetWare software.
  12. **   
  13. **   Novell is not responsible for lost profits or revenue, loss of use
  14. **   of the software, loss of data, costs of re-creating lost data, the
  15. **   cost of any substitute equipment or program, or claims by any party
  16. **   other than you.  Novell strongly recommends a backup be made before
  17. **   any software is installed.   Technical support for this software
  18. **   may be provided at the discretion of Novell.
  19. ****************************************************************************
  20. **
  21. **   File:Dsearch.C
  22. **
  23. **   Desc: This program will use the NWFileSearchInitialize and
  24. **         NWIntSearchContinue functions to get Directory Information from
  25. **         the specified directory.
  26. **
  27. **
  28. **   Programmers:
  29. **   Ini   Who         Firm
  30. **   ------------------------------------------------------------------
  31. **   ARM   A. Ray Maxwell     Novell Developer Support.
  32. **
  33. **   History:
  34. **
  35. **   ------------------------------------------------------------------
  36. **   08-16-95   ARM   First code.
  37. */
  38.  
  39. /***************************************************************************
  40. **   Include headers, macros, function prototypes, etc.
  41. */
  42.  
  43.    /*------------------------------------------------------------------
  44.    **   ANSI
  45.    */
  46.    #include <stdlib.h>          /* exit(), atol()        */
  47.    #include <stdio.h>           /* printf()              */
  48.    #include <string.h>          /* strcpy()              */
  49.    #include <conio.h>           /* clrscr()              */
  50.    #include <mem.h>             /* memset()              */
  51.    /*------------------------------------------------------------------
  52.    **   NetWare
  53.    */
  54.    #include <nwcalls.h>
  55.    #define MAX_BUFFER_LENGTH 80
  56.  
  57. /****************************************************************************
  58. **   Program Start
  59. */
  60. void main(int argc, char *argv[])
  61. {
  62.    NWDIR_HANDLE       dirHandle;
  63.    NWCONN_HANDLE      connHandle;
  64.    NWCCODE            ccode;
  65.    NWPATH_VOL         volNumber;
  66.    NWSEQUENCE_NUM     sequenceNumber;
  67.    NWACCESS_RIGHTS    dirAccessRights;
  68.    NWDIR_NUM          dirID;
  69.    NWSEARCH_ATTR      searchAttributes;    /* SA_SUBDIR_ONLY    */
  70.    char               path[256];
  71.    char               newName[32];
  72.    char               pathString[256] = "";
  73.    char               serverName[48];
  74.    BYTE               buffer          [MAX_BUFFER_LENGTH];
  75.    SEARCH_DIR_INFO    *dirInfo;
  76.  
  77.    /*-----------------------------------------------------------------------
  78.    ** Memory Allocation for struct
  79.    */
  80.    dirInfo = ( SEARCH_DIR_INFO * ) malloc(sizeof( struct SEARCH_DIR_INFO ));
  81.  
  82.    dirInfo = ( SEARCH_DIR_INFO * ) buffer;
  83.  
  84.    /*-----------------------------------------------------------------------
  85.    ** Set Search Attributes
  86.    */
  87.    searchAttributes=0;
  88.    searchAttributes|=SA_SUBDIR_ONLY;
  89.  
  90.  
  91.    if(argc < 2)
  92.       {
  93.       clrscr();
  94.       printf("Usage: SRCHDR <server\\volume:dir\\dir...>\n");
  95.       printf("EXAMPLE DSEARCH MYSERVER\SYS:PUBLIC\\n");
  96.  
  97.       exit(1);
  98.       }
  99.  
  100.    strcpy(pathString, strupr(argv[2]));
  101.  
  102.    ccode = NWCallsInit(NULL, NULL);
  103.    if (ccode)
  104.       {
  105.       printf("\nNWCallsInit returned %04X\n", ccode);
  106.       exit(1);
  107.       }
  108.  
  109.    strupr(argv[1]);
  110.    ccode = NWParseNetWarePath(
  111.            /* > path being parsed               */ argv[1],
  112.            /* < server conn Handle              */ &connHandle,
  113.            /* < directory Handle                */ &dirHandle,
  114.            /* < new path relative to dir Handle */ path);
  115.    if (ccode)
  116.       {
  117.       printf("\nNWParseNetWarePath returned %04X\n", ccode);
  118.       exit(1);
  119.       }
  120.  
  121.    ccode=NWFileSearchInitialize(
  122.          /* connection Handle       */ connHandle,
  123.          /* directory Handle        */ dirHandle,
  124.          /* path                    */ path,
  125.          /* volume Number           */ &volNumber,
  126.          /* volume ID               */ &dirID,
  127.          /* sequence number         */ &sequenceNumber,
  128.          /* directory access rights */ &dirAccessRights);
  129.    if (ccode)
  130.       {
  131.       printf("NWFileSearchInitialize failed: %X.\n",ccode);
  132.       exit(1);
  133.       }
  134.    clrscr();
  135.    printf("Dir Name    Dir Attributes      Seq Number\n");
  136.    do
  137.    {
  138.       ccode=NWIntFileSearchContinue(
  139.          /* connection Handle    */ connHandle,
  140.          /* volume Number        */ volNumber,
  141.          /* directory ID         */ dirID,
  142.          /* search context       */ sequenceNumber,
  143.          /* search Attributes    */ searchAttributes,
  144.          /* search Path          */ "*",
  145.          /* return buffer        */ buffer,
  146.          /* augment flag         */ 0);
  147.  
  148.       if(ccode==0)
  149.       {
  150.  
  151.          printf("%s\t",dirInfo->directoryName);
  152.  
  153.          printf("    [%s%c%s%c%c%c%c]",
  154.             (dirInfo->directoryAttributes & FA_READ_ONLY)      ? "Ro" : "Rw",
  155.             (dirInfo->directoryAttributes & FA_HIDDEN)         ? 'H' : ' ',
  156.             (dirInfo->directoryAttributes & FA_SYSTEM)         ? "Sy" : "-",
  157.             (dirInfo->directoryAttributes & FA_EXECUTE_ONLY)   ? 'X' : '-',
  158.             (dirInfo->directoryAttributes & FA_DIRECTORY)      ? 'D' : '-',
  159.             (dirInfo->directoryAttributes & FA_NEEDS_ARCHIVED) ? 'A' : '-',
  160.             (dirInfo->directoryAttributes & FA_SHAREABLE)      ? 'S' : '-');
  161.  
  162.             printf("          %d\n",sequenceNumber);
  163.       }
  164.  
  165.       sequenceNumber = dirInfo->sequenceNumber;
  166.  
  167.    }                                    /* End of do/while */
  168.    while ( ccode==0);
  169.    switch(ccode)
  170.    {
  171.       case 0X89FF : printf("NWIntFileSearchContinue failed: %X",ccode);
  172.                     printf(" NO_FILES_FOUND_ERROR\n");
  173.                     break;
  174.       case 0X8998 : printf("NWIntFileSearchContinue failed: %X",ccode);
  175.                     printf(" VOLUME_DOES_NOT_EXIST\n");
  176.                     break;
  177.       case 0X8801 : printf("NWIntFileSearchContinue failed: %X",ccode);
  178.                     printf(" INVALID_CONNECTION\n");
  179.                     break;
  180.       default     : printf("NWIntFileSearchContinue failed: %X\n",ccode);
  181.                     break;
  182.    }
  183. }
  184.