home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / c / cd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  2.0 KB  |  107 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: cd.c,v 1.6 1996/10/10 13:12:11 digulla Exp $
  4.     $Log: cd.c,v $
  5.     Revision 1.6  1996/10/10 13:12:11  digulla
  6.     Wrong parameter for Lock()
  7.  
  8.     Revision 1.5  1996/09/17 16:42:59  digulla
  9.     Use general startup code
  10.  
  11.     Revision 1.4  1996/09/13 17:52:09  digulla
  12.     Use IPTR
  13.  
  14.     Revision 1.3  1996/08/13 15:34:04  digulla
  15.     #include <exec/execbase.h> was missing
  16.  
  17.     Revision 1.2  1996/08/01 17:40:43  digulla
  18.     Added standard header for all files
  19.  
  20.     Desc:
  21.     Lang:
  22. */
  23. #include <exec/execbase.h>
  24. #include <exec/memory.h>
  25. #include <clib/exec_protos.h>
  26. #include <dos/dos.h>
  27. #include <clib/dos_protos.h>
  28. #include <utility/tagitem.h>
  29.  
  30. int main (int argc, char ** argv)
  31. {
  32.     STRPTR args[1]={ 0 };
  33.     struct RDArgs *rda;
  34.     BPTR dir;
  35.     STRPTR buf;
  36.     ULONG i;
  37.     struct FileInfoBlock *fib;
  38.     LONG error=0;
  39.  
  40.     rda=ReadArgs("DIR",(IPTR *)args,NULL);
  41.     if(rda!=NULL)
  42.     {
  43.     if(args[0])
  44.     {
  45.         dir=Lock(args[0],SHARED_LOCK);
  46.         if(dir)
  47.         {
  48.         fib=AllocDosObject(DOS_FIB,NULL);
  49.         if(fib!=NULL)
  50.         {
  51.             if(Examine(dir,fib))
  52.             {
  53.             if(fib->fib_DirEntryType>0)
  54.                 dir=CurrentDir(dir);
  55.             else
  56.             {
  57.                 SetIoErr(ERROR_DIR_NOT_FOUND);
  58.                 error=RETURN_ERROR;
  59.             }
  60.             }else
  61.             error=RETURN_ERROR;
  62.             FreeDosObject(DOS_FIB,fib);
  63.         }else
  64.         {
  65.             SetIoErr(ERROR_NO_FREE_STORE);
  66.             error=RETURN_ERROR;
  67.         }
  68.         UnLock(dir);
  69.         }else
  70.         error=RETURN_ERROR;
  71.     }else
  72.     {
  73.         dir=CurrentDir(0);
  74.         for(i=256;;i+=256)
  75.         {
  76.         buf=AllocVec(i,MEMF_ANY);
  77.         if(buf==NULL)
  78.         {
  79.             SetIoErr(ERROR_NO_FREE_STORE);
  80.             error=RETURN_ERROR;
  81.             break;
  82.         }
  83.         if(NameFromLock(dir,buf,i))
  84.         {
  85.             if(FPuts(Output(),buf)<0||
  86.                FPuts(Output(),"\n")<0)
  87.             error=RETURN_ERROR;
  88.             FreeVec(buf);
  89.             break;
  90.         }
  91.         FreeVec(buf);
  92.         if(IoErr()!=ERROR_LINE_TOO_LONG)
  93.         {
  94.             error=RETURN_ERROR;
  95.             break;
  96.         }
  97.         }
  98.         CurrentDir(dir);
  99.     }
  100.     FreeArgs(rda);
  101.     }else
  102.     error=RETURN_FAIL;
  103.     if(error)
  104.     PrintFault(IoErr(),"CD");
  105.     return error;
  106. }
  107.