revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / datatypes / launchtoola.c
blob69ff05728d46a27fa4ea68e06a65fa3760e61c0e
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "datatypes_intern.h"
7 #include <datatypes/datatypesclass.h>
8 #include <utility/tagitem.h>
9 #include <dos/dostags.h>
10 #include <proto/alib.h>
11 #include <proto/dos.h>
12 #include <proto/exec.h>
13 #include <proto/utility.h>
14 #include <proto/workbench.h>
16 /* Putchar procedure needed by RawDoFmt() */
18 AROS_UFH2(void, dt_putchr,
19 AROS_UFHA(UBYTE, chr, D0),
20 AROS_UFHA(STRPTR *, p, A3))
22 AROS_USERFUNC_INIT
23 *(*p)++ = chr;
24 AROS_USERFUNC_EXIT
27 void dt__sprintf(struct Library *DataTypesBase, UBYTE *buffer,
28 UBYTE *format, ...)
30 AROS_SLOWSTACKFORMAT_PRE(format);
31 RawDoFmt(format, AROS_SLOWSTACKFORMAT_ARG(format), (VOID_FUNC)dt_putchr, &buffer);
32 AROS_SLOWSTACKFORMAT_POST(format);
36 /*****************************************************************************
38 NAME */
39 #include <proto/datatypes.h>
41 AROS_LH3(ULONG, LaunchToolA,
43 /* SYNOPSIS */
44 AROS_LHA(struct Tool * , tool, A0),
45 AROS_LHA(STRPTR , project, A1),
46 AROS_LHA(struct TagItem *, attrs, A2),
48 /* LOCATION */
49 struct Library *, DataTypesBase, 42, DataTypes)
51 /* FUNCTION
53 Launch an application with a particular project.
55 INPUTS
57 tool -- tool to use (may be NULL in which case this function
58 returns 0)
59 project -- name of the project to execute or NULL
60 attrs -- additional attributes
62 TAGS
64 NP_Priority (BYTE) -- priority of the launched tool (default is the
65 priority of the currect process except for
66 Workbench applications where the default priority
67 is 0 if not overridden by the TOOLPRI tooltype).
69 NP_Synchronous (BOOL) -- don't return until lauched application process
70 finishes (defaults to FALSE).
72 RESULT
74 Zero for failure, non-zero otherwise.
76 NOTES
78 EXAMPLE
80 BUGS
82 SEE ALSO
84 NewDTObjectA()
86 INTERNALS
88 *****************************************************************************/
90 AROS_LIBFUNC_INIT
92 BOOL isSynchronous;
93 BPTR output;
95 if (tool == NULL)
97 SetIoErr(ERROR_REQUIRED_ARG_MISSING);
99 return 0;
102 isSynchronous = (BOOL)GetTagData(NP_Synchronous, (IPTR)FALSE, attrs);
104 switch (tool->tn_Flags & TF_LAUNCH_MASK)
106 case TF_SHELL:
108 char tBuffer[512];
109 LONG ret;
111 dt__sprintf
113 DataTypesBase, tBuffer,
114 "\"%s\" \"%s\"", tool->tn_Program, project
117 output = Open("CON:////Output window/AUTO/WAIT/CLOSE/INACTIVE",
118 MODE_NEWFILE);
120 if (output != BNULL)
122 struct TagItem tags[] = { { SYS_Asynch, !isSynchronous },
123 { SYS_Input , (IPTR)NULL },
124 { SYS_Output, (IPTR)output },
125 { TAG_DONE, } };
128 ret = SystemTagList(tBuffer, tags);
130 /* Error? */
131 if (ret == -1)
133 return 0;
136 Close(output);
138 else
140 return 0;
144 break;
146 case TF_WORKBENCH:
148 BOOL success = FALSE;
149 struct Library *WorkbenchBase = OpenLibrary("workbench.library", 39L);
151 if (WorkbenchBase != NULL)
153 BPTR lock = Lock(project, ACCESS_READ);
155 if (lock != BNULL)
157 BPTR parent = ParentDir(lock);
159 success = OpenWorkbenchObject
161 tool->tn_Program,
162 WBOPENA_ArgLock, (IPTR) parent,
163 WBOPENA_ArgName, (IPTR) FilePart(project),
164 TAG_DONE
167 UnLock(lock);
170 CloseLibrary(WorkbenchBase);
173 if (!success) return 0;
175 break;
177 case TF_RX:
178 /* Sorry, no Arexx in AROS yet. */
179 /* FIXME: No Arexx compatibility yet */
181 /* Do some "RX command" here */
182 return 0;
184 default:
185 return 0;
188 return 1;
190 AROS_LIBFUNC_EXIT
191 } /* LaunchToolA */