home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Shareware (Platinum Edition) / QUEPLAT95.ISO / files / programm / lfnlib / lfntest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-23  |  2.2 KB  |  89 lines

  1. //lfntest.c             simple demonstration of the LFN module's capabilities
  2. //created 5-25-95       Matt Ginzton
  3.  
  4. //(c) 1995 Matt Ginzton, MaDdoG Software
  5. //permission is granted to use and modify this code as long as attribution
  6. //is given.  Questions?  Email mginzton@leland.stanford.edu, or via
  7. //CompuServe, 75022,650.
  8.  
  9. //lfntest simulates a SIMPLE! DOS shell like command.com.  It only supports
  10. //cd, dir, and x: (to change drives).  It doesn't look at any arguments to the
  11. //dir command, either.
  12. //
  13. //But it does support long filenames under Windows 95, and runs fine happily
  14. //with short filenames under other versions of Windows!
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <ctype.h>
  19. #include <direct.h>
  20. #include "lfn.h"
  21. #include <dos.h>
  22.  
  23. int Interact (char * buf, int size);
  24. void Dir(void);
  25.  
  26.  
  27. void main (void)
  28. {
  29.     char buffer[200];
  30.     
  31.     _lfn_init ('C');
  32.     
  33.     while (Interact (buffer, sizeof(buffer)-1))
  34.     {
  35.         if (buffer[1]==':')
  36.         {
  37.             if (_chdrive (toupper(buffer[0])-'A'+1))
  38.             {
  39.                 printf ("Can't change to drive %c.\n", buffer[0]);
  40.                 continue;   //error
  41.             }
  42.             _lfn_init (buffer[0]);
  43.         }
  44.         else if (!strnicmp (buffer, "cd", 2))
  45.         {
  46.             _lfn_chdir (buffer+3);
  47.         }
  48.         else if (!strnicmp (buffer, "dir", 3))
  49.         {
  50.             Dir();
  51.         }
  52.         else if (!strnicmp (buffer, "exit", 4))
  53.         {
  54.             break;
  55.         }
  56.         else
  57.         {
  58.             printf ("Unrecognized command.  Keep it simple, stupid!\n");
  59.         }
  60.     }
  61. }
  62.  
  63.  
  64. int Interact (char * buf, int size)
  65. {
  66.     _lfn_getcwd (buf, size);
  67.     printf ("%s> ", buf);
  68.     fgets (buf, size, stdin);
  69.     *(buf+strlen(buf)-1)=0; //get rid of \n character
  70.     if (!*buf)
  71.         return 0;
  72.     return 1;
  73. }
  74.  
  75.  
  76. void Dir (void)
  77. {
  78.     int err;
  79.     _lfnfind_t fileinfo;
  80.  
  81.     err=_lfn_findfirst ("*.*", _A_NORMAL | _A_HIDDEN | _A_RDONLY | _A_ARCH | _A_SUBDIR, &fileinfo);
  82.     while (!err)
  83.     {
  84.         printf (fileinfo.SFN.attrib & _A_SUBDIR ? "[%-38s]\t%lu\n" : "%-40s\t%lu\n", fileinfo.name, fileinfo.SFN.size);
  85.         err=_lfn_findnext (&fileinfo);
  86.     }
  87.     _lfn_findclose (&fileinfo);
  88. }
  89.