Update to lasso handling. Adjust scroll amount based on difference between mouse...
[AROS.git] / rom / dos / allocdosobject.c
blob315e6bb3ca1614ba166b42aab22164dd0a9214d3
1 /*
2 Copyright © 1995-2008, 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(const 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 APTR mem;
58 switch(type)
60 case DOS_FILEHANDLE:
61 mem = AllocMem(sizeof(struct FileHandle), MEMF_CLEAR);
63 if (mem != NULL)
65 struct FileHandle *fh = (struct FileHandle *)mem;
67 /* We set fh->fh_Arg1 to point back to 'fh' to make packet
68 emulation possible */
69 fh->fh_CompatibilityHack = (SIPTR)fh;
71 return mem;
73 case DOS_FIB:
74 return AllocMem(sizeof(struct FileInfoBlock), MEMF_CLEAR);
76 case DOS_STDPKT:
78 struct StandardPacket *sp = AllocMem(sizeof(struct StandardPacket), MEMF_CLEAR);
80 if (sp == NULL)
81 return NULL;
83 sp->sp_Pkt.dp_Link = &(sp->sp_Msg);
84 sp->sp_Msg.mn_Node.ln_Name = (char *) &(sp->sp_Pkt);
86 return (APTR) &(sp->sp_Pkt);
89 case DOS_EXALLCONTROL:
90 return AllocMem(sizeof(struct InternalExAllControl), MEMF_CLEAR);
92 case DOS_CLI:
94 struct CommandLineInterface *cli = NULL;
95 struct TagItem defaults[] =
97 /* 0 */ { ADO_DirLen, 255 },
98 /* 1 */ { ADO_CommNameLen, 255 },
99 /* 2 */ { ADO_CommFileLen, 255 },
100 /* 3 */ { ADO_PromptLen, 255 },
101 { TAG_END, 0 }
104 STRPTR dir = NULL;
105 STRPTR command = NULL;
106 STRPTR file = NULL;
107 STRPTR prompt = NULL;
109 /* C has no exceptions. This is a simple replacement. */
110 #define ENOMEM_IF(a) if(a) goto enomem /* Throw out of memory. */
112 cli = AllocMem(sizeof(struct CommandLineInterface), MEMF_CLEAR);
113 ENOMEM_IF(cli == NULL);
115 cli->cli_FailLevel = RETURN_ERROR;
116 cli->cli_Background = DOSTRUE;
117 ApplyTagChanges(defaults, tags);
119 dir = AllocVec(defaults[0].ti_Data + 1, MEMF_PUBLIC | MEMF_CLEAR);
120 ENOMEM_IF(dir == NULL);
122 AROS_BSTR_setstrlen(MKBADDR(dir), 0);
123 cli->cli_SetName = MKBADDR(dir);
125 command = AllocVec(defaults[1].ti_Data + 1,
126 MEMF_PUBLIC | MEMF_CLEAR);
127 ENOMEM_IF(command == NULL);
129 AROS_BSTR_setstrlen(MKBADDR(command), 0);
130 cli->cli_CommandName = MKBADDR(command);
132 file = AllocVec(defaults[2].ti_Data + 1, MEMF_PUBLIC | MEMF_CLEAR);
133 ENOMEM_IF(file == NULL);
135 AROS_BSTR_setstrlen(MKBADDR(file), 0);
136 cli->cli_CommandFile = MKBADDR(file);
138 prompt = AllocVec(defaults[3].ti_Data + 1,
139 MEMF_PUBLIC | MEMF_CLEAR);
140 ENOMEM_IF(prompt == NULL);
142 AROS_BSTR_setstrlen(MKBADDR(prompt), 0);
143 cli->cli_Prompt = MKBADDR(prompt);
145 return cli;
147 enomem:
148 if(cli != NULL)
149 FreeMem(cli, sizeof(struct CommandLineInterface));
151 FreeVec(dir);
152 FreeVec(command);
153 FreeVec(file);
154 FreeVec(prompt);
156 SetIoErr(ERROR_NO_FREE_STORE);
158 return NULL;
161 case DOS_RDARGS:
162 return AllocVec(sizeof(struct RDArgs), MEMF_CLEAR);
165 SetIoErr(ERROR_BAD_NUMBER);
167 return NULL;
169 AROS_LIBFUNC_EXIT
170 } /* AllocDosObject */