Turkish Q Standard PC105 Keymap
[AROS.git] / rom / dos / allocdosobject.c
blob676781f70d57c88cd2289cda21958fe4a10b2efa
1 /*
2 Copyright © 1995-2011, 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 fh->fh_Pos = -1;
68 fh->fh_End = -1;
70 return mem;
72 case DOS_FIB:
73 return AllocMem(sizeof(struct FileInfoBlock), MEMF_CLEAR);
75 case DOS_STDPKT:
76 return allocdospacket();
78 case DOS_EXALLCONTROL:
79 return AllocMem(sizeof(struct InternalExAllControl), MEMF_CLEAR);
81 case DOS_CLI:
83 struct CommandLineInterface *cli = NULL;
84 struct TagItem defaults[] =
86 /* 0 */ { ADO_DirLen, 255 },
87 /* 1 */ { ADO_CommNameLen, 255 },
88 /* 2 */ { ADO_CommFileLen, 255 },
89 /* 3 */ { ADO_PromptLen, 255 },
90 { TAG_END, 0 }
93 STRPTR dir = NULL;
94 STRPTR command = NULL;
95 STRPTR file = NULL;
96 STRPTR prompt = NULL;
98 /* C has no exceptions. This is a simple replacement. */
99 #define ENOMEM_IF(a) if(a) goto enomem /* Throw out of memory. */
101 cli = AllocMem(sizeof(struct CommandLineInterface), MEMF_CLEAR);
102 ENOMEM_IF(cli == NULL);
104 cli->cli_FailLevel = RETURN_ERROR;
105 cli->cli_Background = DOSTRUE;
106 ApplyTagChanges(defaults, (struct TagItem *)tags);
108 dir = AllocVec(defaults[0].ti_Data + 1, MEMF_PUBLIC | MEMF_CLEAR);
109 ENOMEM_IF(dir == NULL);
111 AROS_BSTR_setstrlen(MKBADDR(dir), 0);
112 cli->cli_SetName = MKBADDR(dir);
114 command = AllocVec(defaults[1].ti_Data + 1,
115 MEMF_PUBLIC | MEMF_CLEAR);
116 ENOMEM_IF(command == NULL);
118 AROS_BSTR_setstrlen(MKBADDR(command), 0);
119 cli->cli_CommandName = MKBADDR(command);
121 file = AllocVec(defaults[2].ti_Data + 1, MEMF_PUBLIC | MEMF_CLEAR);
122 ENOMEM_IF(file == NULL);
124 AROS_BSTR_setstrlen(MKBADDR(file), 0);
125 cli->cli_CommandFile = MKBADDR(file);
127 prompt = AllocVec(defaults[3].ti_Data + 1,
128 MEMF_PUBLIC | MEMF_CLEAR);
129 ENOMEM_IF(prompt == NULL);
131 AROS_BSTR_setstrlen(MKBADDR(prompt), 0);
132 cli->cli_Prompt = MKBADDR(prompt);
134 return cli;
136 enomem:
137 if(cli != NULL)
138 FreeMem(cli, sizeof(struct CommandLineInterface));
140 FreeVec(dir);
141 FreeVec(command);
142 FreeVec(file);
143 FreeVec(prompt);
145 SetIoErr(ERROR_NO_FREE_STORE);
147 return NULL;
150 case DOS_RDARGS:
151 return AllocVec(sizeof(struct RDArgs), MEMF_CLEAR);
154 SetIoErr(ERROR_BAD_NUMBER);
156 return NULL;
158 AROS_LIBFUNC_EXIT
159 } /* AllocDosObject */
161 /* Internal routines for packet allocation. Does not require DOSBase. */
162 struct DosPacket *allocdospacket(void)
164 struct StandardPacket *sp = AllocMem(sizeof(struct StandardPacket), MEMF_CLEAR);
166 if (sp == NULL)
167 return NULL;
169 sp->sp_Pkt.dp_Link = &sp->sp_Msg;
170 sp->sp_Msg.mn_Node.ln_Name = (char *)&sp->sp_Pkt;
172 return &sp->sp_Pkt;