New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / dos / allocdosobject.c
blob0278f1dcc622702d298723b9fbb1b327ed8b37eb
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <dos/exall.h>
11 #include <utility/tagitem.h>
12 #include <proto/utility.h>
13 #include <dos/rdargs.h>
14 #include <dos/dostags.h>
15 #include "dos_intern.h"
17 /*****************************************************************************
19 NAME */
20 #include <proto/dos.h>
22 AROS_LH2(APTR, AllocDosObject,
24 /* SYNOPSIS */
25 AROS_LHA(ULONG , type, D1),
26 AROS_LHA(struct TagItem *, tags, D2),
28 /* LOCATION */
29 struct DosLibrary *, DOSBase, 38, Dos)
31 /* FUNCTION
32 Creates a new dos object of a given type. This memory has to be
33 freed with FreeDosObject().
35 INPUTS
36 type - Object type.
37 tags - Pointer to taglist array with additional information. See
38 <dos/dostags.h> for a list of all supported tags.
40 RESULT
41 Pointer to new object or NULL, to indicate an error.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
51 INTERNALS
53 *****************************************************************************/
55 AROS_LIBFUNC_INIT
56 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
57 APTR mem;
59 switch(type)
61 case DOS_FILEHANDLE:
62 mem = AllocMem(sizeof(struct FileHandle), MEMF_CLEAR);
64 if (mem != NULL)
66 struct FileHandle *fh = (struct FileHandle *)mem;
68 /* We set fh->fh_Arg1 to point back to 'fh' to make packet
69 emulation possible */
70 fh->fh_CompatibilityHack = fh;
72 else
74 SetIoErr(ERROR_NO_FREE_STORE);
77 return mem;
79 case DOS_FIB:
80 mem = AllocMem(sizeof(struct FileInfoBlock), MEMF_CLEAR);
82 if(mem == NULL)
83 SetIoErr(ERROR_NO_FREE_STORE);
85 return mem;
87 case DOS_STDPKT:
88 mem = AllocMem(sizeof(struct StandardPacket), MEMF_CLEAR);
90 if (mem == NULL)
91 SetIoErr(ERROR_NO_FREE_STORE);
93 return &((struct StandardPacket *)mem)->sp_Pkt;
95 case DOS_EXALLCONTROL:
96 mem = AllocMem(sizeof(struct InternalExAllControl), MEMF_CLEAR);
98 if(mem == NULL)
99 SetIoErr(ERROR_NO_FREE_STORE);
101 return mem;
103 case DOS_CLI:
105 struct CommandLineInterface *cli = NULL;
106 struct TagItem defaults[] =
108 /* 0 */ { ADO_DirLen, 255 },
109 /* 1 */ { ADO_CommNameLen, 255 },
110 /* 2 */ { ADO_CommFileLen, 255 },
111 /* 3 */ { ADO_PromptLen, 255 },
112 { TAG_END, 0 }
115 STRPTR dir = NULL;
116 STRPTR command = NULL;
117 STRPTR file = NULL;
118 STRPTR prompt = NULL;
120 /* C has no exceptions. This is a simple replacement. */
121 #define ENOMEM_IF(a) if(a) goto enomem /* Throw out of memory. */
123 cli = AllocMem(sizeof(struct CommandLineInterface), MEMF_CLEAR);
124 ENOMEM_IF(cli == NULL);
126 cli->cli_FailLevel = RETURN_ERROR;
127 cli->cli_Background = DOSTRUE;
128 ApplyTagChanges(defaults, tags);
130 dir = AllocVec(defaults[0].ti_Data + 1, MEMF_PUBLIC | MEMF_CLEAR);
131 ENOMEM_IF(dir == NULL);
133 cli->cli_SetName = MKBADDR(dir);
135 command = AllocVec(defaults[1].ti_Data + 1,
136 MEMF_PUBLIC | MEMF_CLEAR);
137 ENOMEM_IF(command == NULL);
139 cli->cli_CommandName = MKBADDR(command);
141 file = AllocVec(defaults[2].ti_Data + 1, MEMF_PUBLIC | MEMF_CLEAR);
142 ENOMEM_IF(file == NULL);
144 cli->cli_CommandFile = MKBADDR(file);
146 prompt = AllocVec(defaults[3].ti_Data + 1,
147 MEMF_PUBLIC | MEMF_CLEAR);
148 ENOMEM_IF(prompt == NULL);
150 cli->cli_Prompt = MKBADDR(prompt);
152 return cli;
154 enomem:
155 if(cli != NULL)
156 FreeMem(cli, sizeof(struct CommandLineInterface));
158 FreeVec(dir);
159 FreeVec(command);
160 FreeVec(file);
161 FreeVec(prompt);
163 SetIoErr(ERROR_NO_FREE_STORE);
165 return NULL;
168 case DOS_RDARGS:
169 return AllocVec(sizeof(struct RDArgs), MEMF_CLEAR);
172 SetIoErr(ERROR_BAD_NUMBER);
174 return NULL;
176 AROS_LIBFUNC_EXIT
177 } /* AllocDosObject */