home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 376_01 / os2tool.000 / DIRSDOS.C < prev    next >
C/C++ Source or Header  |  1992-03-03  |  2KB  |  81 lines

  1. /* =====================================================
  2. *
  3. * DIRSDOS.C  - Show the directory stack.
  4. *
  5. *
  6. * Copyright(c): Martti Ylikoski. 1992
  7. *
  8. * Programmer:    Martti Ylikoski
  9. * Created:    3.3.1992
  10. * Version:    1.0
  11. *
  12. * ====================================================== */
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "list.h"
  17.  
  18. static char *deffile = "C:\\dirserv.dat" ;
  19.  
  20. int main(int argc, char * argv[])
  21. {
  22. HNDLIST *lhandle ;
  23. int i, actioncode, popid ;
  24. char * buf, fbuff[125], *tmp ;
  25. unsigned long buflen ;
  26. FILE *fp ;
  27.  
  28.    popid = 1 ;
  29.  
  30.    if ( (tmp = getenv("DIRSERV")) != NULL)
  31.       deffile = tmp ;
  32.    
  33.    if (argc == 2 && (strcmpi(argv[1], "-q") == 0
  34.        || strcmpi(argv[1], "/q") == 0))
  35.    {
  36.       unlink (deffile) ;
  37.       printf("Directory stack server removed. \n") ;
  38.       return( 0 ) ;
  39.    }
  40.    
  41.    if (argc == 2)
  42.       popid = atoi(argv[1]) ;
  43.  
  44.    if ((lhandle = ListInit()) == NULL)
  45.    {
  46.       printf("Error in ListInit\nExit\n") ;
  47.       return( 1 ) ;
  48.    }
  49.  
  50.    if ((fp = fopen (deffile, "r")) == NULL)
  51.    {
  52.       printf("[%1] .\n") ;   
  53.       return( 0 ) ;
  54.    }
  55.  
  56.    while (fgets(fbuff, sizeof(fbuff), fp ) != NULL)
  57.    {
  58.       ListAdd(lhandle, fbuff, strlen(fbuff)+1) ; /* +1 because we store also \0 */
  59.     }
  60.  
  61.    fclose (fp) ;
  62.    
  63.  
  64.    i = 1 ;
  65.    ListLast(lhandle) ;
  66.    while ( ListReturn(lhandle, &buf, &buflen) == LIST_OK)
  67.    {
  68.       printf("[%d] %s", i, buf) ;
  69.  
  70.       i++ ;
  71.  
  72.       if ( ListPrior(lhandle) == LIST_ERR_BEG_LIST)
  73.          break ;
  74.    }
  75.  
  76.    printf("[%d] .\n", i) ;   
  77.  
  78.    return( 0 ) ;   
  79. }
  80.