New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / shellcommands / CD.c
blobca0c252f21fbc45c79b1554d839c8414a0110649
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: CD CLI command
6 Lang: English
7 */
8 /*****************************************************************************
10 NAME
14 SYNOPSIS
16 DIR
18 LOCATION
20 Workbench:C/
22 FUNCTION
24 Without argument it shows the name of the current directory.
25 With argument it changes the current directory.
27 INPUTS
29 DIR -- path to change to current directory
31 RESULT
33 EXAMPLE
35 BUGS
37 SEE ALSO
39 INTERNALS
41 HISTORY
43 ******************************************************************************/
45 #include <exec/execbase.h>
46 #include <exec/memory.h>
47 #include <proto/exec.h>
48 #include <dos/dos.h>
49 #include <proto/dos.h>
51 #include <aros/shcommands.h>
53 AROS_SH1(CD, 41.1,
54 AROS_SHA(STRPTR, ,DIR, ,NULL))
56 AROS_SHCOMMAND_INIT
58 BPTR dir,newdir;
59 STRPTR buf;
60 ULONG i;
61 struct FileInfoBlock *fib;
62 LONG error = 0;
65 if (SHArg(DIR))
67 dir = Lock(SHArg(DIR), SHARED_LOCK);
69 if (dir)
71 fib = AllocDosObject(DOS_FIB, NULL);
73 if (fib != NULL)
75 if (Examine(dir, fib))
77 if (fib->fib_DirEntryType > 0)
79 newdir = dir;
80 dir = CurrentDir(newdir);
82 for (i = 256;;i += 256)
84 buf = AllocVec(i, MEMF_ANY);
86 if (buf == NULL)
88 SetIoErr(ERROR_NO_FREE_STORE);
89 error = RETURN_ERROR;
90 break;
93 if (NameFromLock(newdir, buf, i))
95 SetCurrentDirName(buf);
96 FreeVec(buf);
97 break;
100 FreeVec(buf);
102 if (IoErr() != ERROR_LINE_TOO_LONG)
104 error = RETURN_ERROR;
105 break;
109 else
111 SetIoErr(ERROR_OBJECT_WRONG_TYPE);
112 error = RETURN_ERROR;
115 else
117 error = RETURN_ERROR;
120 FreeDosObject(DOS_FIB, fib);
122 else
124 SetIoErr(ERROR_NO_FREE_STORE);
125 error = RETURN_ERROR;
128 UnLock(dir);
130 else
132 error = RETURN_ERROR;
135 else
137 dir = CurrentDir(NULL);
139 for(i = 256;;i += 256)
141 buf = AllocVec(i, MEMF_ANY);
143 if (buf == NULL)
145 SetIoErr(ERROR_NO_FREE_STORE);
146 error = RETURN_ERROR;
147 break;
150 if (NameFromLock(dir, buf, i))
152 if (FPuts(Output(), buf) < 0 || FPuts(Output(), "\n") < 0)
154 error = RETURN_ERROR;
157 FreeVec(buf);
158 break;
161 FreeVec(buf);
163 if (IoErr() != ERROR_LINE_TOO_LONG)
165 error = RETURN_ERROR;
166 break;
170 CurrentDir(dir);
173 if (error)
175 PrintFault(IoErr(), "CD");
178 return error;
180 AROS_SHCOMMAND_EXIT