2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
6 #ifndef SHCOMMANDS_EMBEDDED_H
7 #define SHCOMMANDS_EMBEDDED_H
10 #include <dos/rdargs.h>
11 #include <proto/dos.h>
12 #include <proto/exec.h>
13 #include <aros/asmcall.h>
15 #define _stringify(x) #x
16 #define stringify(x) _stringify(x)
18 #if (AROS_FLAVOUR & AROS_FLAVOUR_NATIVE)
19 # define AMIGANATIVETRICK \
21 "\tmove.l 4.w,a6 \n" \
22 "\tjra __entry(pc) \n");
24 # define AMIGANATIVETRICK
28 # define DECLARE_DOSBase_global extern struct DosLibrary *DOSBase;
29 # define DEFINE_DOSBase_global struct DosLibrary *DOSBase;
30 # define DEFINE_DOSBase_local
32 # define DECLARE_DOSBase_global
33 # define DEFINE_DOSBase_local struct DosLibrary *DOSBase;
34 # define DEFINE_DOSBase_global
37 #define CALL_main(name) name##_main(__shargs, argstr, SysBase, DOSBase)
38 #define DECLARE_main(name) \
39 static ULONG name##_main(IPTR *__shargs, char * __argstr, \
40 struct ExecBase *SysBase, \
41 struct DosLibrary *DOSBase)
42 #define DEFINE_main(name) DECLARE_main(name)
44 #define SHArg(name) (*(SHA_##name##_type *)&__shargs[SHA_##name])
45 #define SHArgLine() __argstr
47 #define __SHA_ENUM(type, abbr, name, modf, def, help) SHA_##name
48 #define __SHA_DEF(type, abbr, name, modf, def, help) (IPTR)(def)
49 #define __SHA_OPT(type, abbr, name, modf, def, help) \
50 stringify(abbr) stringify(name) stringify(modf)
51 #define __SHA_TYPEDEF(type, abbr, name, modf, def, help) \
52 typedef type SHA_##name##_type
55 #define __AROS_SH_ARGS(name, version, numargs, defl, templ, help) \
58 DECLARE_DOSBase_global \
60 AROS_UFH3(__startup static LONG, _entry, \
61 AROS_UFHA(char *,argstr,A0), \
62 AROS_UFHA(ULONG,argsize,D0), \
63 AROS_UFHA(struct ExecBase *,SysBase,A6) \
68 DEFINE_DOSBase_local \
70 LONG __retcode = RETURN_FAIL; \
71 IPTR __shargs[numargs] = defl; \
72 struct RDArgs *__rda = NULL; \
73 struct RDArgs *__rda2 = NULL; \
75 DOSBase = (struct DosLibrary *) OpenLibrary(DOSNAME, 37); \
79 SetIoErr(ERROR_INVALID_RESIDENT_LIBRARY); \
85 __rda2 = (struct RDArgs *)AllocDosObject(DOS_RDARGS, NULL); \
88 PrintFault(IoErr(), stringify(name)); \
91 __rda2->RDA_ExtHelp = help; \
94 __rda = ReadArgs(templ, __shargs, __rda2); \
98 PrintFault(IoErr(), stringify(name)); \
102 __retcode = CALL_main(name); \
105 if (__rda) FreeArgs(__rda); \
106 if (help[0] && __rda2) FreeDosObject(DOS_RDARGS, __rda2); \
107 if (DOSBase) CloseLibrary((struct Library *)DOSBase); \
114 DEFINE_DOSBase_global \
116 __used static const UBYTE name##_version[] = "$VER: " \
117 stringify(name) " " \
118 stringify(version) " " \
119 "(" __DATE__ ")\n"; \
124 #define AROS_SHCOMMAND_INIT
126 #define AROS_SHCOMMAND_EXIT \
130 #define __DEF(x...) {x}
132 #define __AROS_SH0(name, version, help) \
133 __AROS_SH_ARGS(name, version, 1, {0}, "", help) \
136 #define __AROS_SH1(name, version, help, a1) \
137 __AROS_SH_ARGS(name, version, 1, \
138 __DEF(__SHA_DEF(a1)), \
143 enum {__SHA_ENUM(a1)};
145 #define __AROS_SH2(name, version, help, a1, a2) \
146 __AROS_SH_ARGS(name, version, 2, \
147 __DEF(__SHA_DEF(a1), __SHA_DEF(a2)), \
148 __SHA_OPT(a1) "," __SHA_OPT(a2), \
153 enum {__SHA_ENUM(a1), __SHA_ENUM(a2)};
155 #define __AROS_SH3(name, version, help, a1, a2, a3) \
156 __AROS_SH_ARGS(name, version, 3, \
157 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
159 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
166 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), \
169 #define __AROS_SH4(name, version, help, a1, a2, a3, a4) \
170 __AROS_SH_ARGS(name, version, 4, \
171 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
172 __SHA_DEF(a3), __SHA_DEF(a4)), \
173 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
174 __SHA_OPT(a3) "," __SHA_OPT(a4), \
181 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), \
182 __SHA_ENUM(a3), __SHA_ENUM(a4)};
184 #define __AROS_SH5(name, version, help, a1, a2, a3, a4, a5) \
185 __AROS_SH_ARGS(name, version, 5, \
186 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
187 __SHA_DEF(a3), __SHA_DEF(a4), \
189 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
190 __SHA_OPT(a3) "," __SHA_OPT(a4) "," \
199 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), __SHA_ENUM(a3), \
200 __SHA_ENUM(a4), __SHA_ENUM(a5)};
202 #define __AROS_SH6(name, version, help, a1, a2, a3, a4, a5, a6) \
203 __AROS_SH_ARGS(name, version, 6, \
204 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
205 __SHA_DEF(a3), __SHA_DEF(a4), \
206 __SHA_DEF(a5), __SHA_DEF(a6)), \
207 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
208 __SHA_OPT(a3) "," __SHA_OPT(a4) "," \
209 __SHA_OPT(a5) "," __SHA_OPT(a6), \
218 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), __SHA_ENUM(a3), \
219 __SHA_ENUM(a4), __SHA_ENUM(a5), __SHA_ENUM(a6)};
221 #define __AROS_SH7(name, version, help, a1, a2, a3, a4, a5, \
223 __AROS_SH_ARGS(name, version, 7, \
224 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
225 __SHA_DEF(a3), __SHA_DEF(a4), \
226 __SHA_DEF(a5), __SHA_DEF(a6), \
228 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
229 __SHA_OPT(a3) "," __SHA_OPT(a4) "," \
230 __SHA_OPT(a5) "," __SHA_OPT(a6) "," \
241 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), __SHA_ENUM(a3), \
242 __SHA_ENUM(a4), __SHA_ENUM(a5), __SHA_ENUM(a6), \
245 #define __AROS_SH8(name, version, help, a1, a2, a3, a4, a5, \
247 __AROS_SH_ARGS(name, version, 8, \
248 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
249 __SHA_DEF(a3), __SHA_DEF(a4), \
250 __SHA_DEF(a5), __SHA_DEF(a6), \
251 __SHA_DEF(a7), __SHA_DEF(a8)), \
252 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
253 __SHA_OPT(a3) "," __SHA_OPT(a4) "," \
254 __SHA_OPT(a5) "," __SHA_OPT(a6) "," \
255 __SHA_OPT(a7) "," __SHA_OPT(a8), \
266 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), __SHA_ENUM(a3), \
267 __SHA_ENUM(a4), __SHA_ENUM(a5), __SHA_ENUM(a6), \
268 __SHA_ENUM(a7), __SHA_ENUM(a8)};
271 #define __AROS_SH10(name, version, help, a1, a2, a3, a4, a5, \
272 a6, a7, a8, a9, a10) \
273 __AROS_SH_ARGS(name, version, 10, \
274 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
275 __SHA_DEF(a3), __SHA_DEF(a4), \
276 __SHA_DEF(a5), __SHA_DEF(a6), \
277 __SHA_DEF(a7), __SHA_DEF(a8), \
278 __SHA_DEF(a9), __SHA_DEF(a10)), \
279 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
280 __SHA_OPT(a3) "," __SHA_OPT(a4) "," \
281 __SHA_OPT(a5) "," __SHA_OPT(a6) "," \
282 __SHA_OPT(a7) "," __SHA_OPT(a8) "," \
283 __SHA_OPT(a9) "," __SHA_OPT(a10), \
295 __SHA_TYPEDEF(a10); \
296 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), __SHA_ENUM(a3), \
297 __SHA_ENUM(a4), __SHA_ENUM(a5), __SHA_ENUM(a6), \
298 __SHA_ENUM(a7), __SHA_ENUM(a8), __SHA_ENUM(a9), \
301 #define __AROS_SH11(name, version, help, a1, a2, a3, a4, a5, \
302 a6, a7, a8, a9, a10, \
304 __AROS_SH_ARGS(name, version, 11, \
305 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
306 __SHA_DEF(a3), __SHA_DEF(a4), \
307 __SHA_DEF(a5), __SHA_DEF(a6), \
308 __SHA_DEF(a7), __SHA_DEF(a8), \
309 __SHA_DEF(a9), __SHA_DEF(a10), \
311 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
312 __SHA_OPT(a3) "," __SHA_OPT(a4) "," \
313 __SHA_OPT(a5) "," __SHA_OPT(a6) "," \
314 __SHA_OPT(a7) "," __SHA_OPT(a8) "," \
315 __SHA_OPT(a9) "," __SHA_OPT(a10) "." \
316 __SHA_OPT(a11), help) \
327 __SHA_TYPEDEF(a10); \
328 __SHA_TYPEDEF(a11); \
329 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), __SHA_ENUM(a3), \
330 __SHA_ENUM(a4), __SHA_ENUM(a5), __SHA_ENUM(a6), \
331 __SHA_ENUM(a7), __SHA_ENUM(a8), __SHA_ENUM(a9), \
332 __SHA_ENUM(a10), __SHA_ENUM(a11)};
334 #define __AROS_SH12(name, version, help, a1, a2, a3, a4, a5, \
335 a6, a7, a8, a9, a10, \
337 __AROS_SH_ARGS(name, version, 12, \
338 __DEF(__SHA_DEF(a1), __SHA_DEF(a2), \
339 __SHA_DEF(a3), __SHA_DEF(a4), \
340 __SHA_DEF(a5), __SHA_DEF(a6), \
341 __SHA_DEF(a7), __SHA_DEF(a8), \
342 __SHA_DEF(a9), __SHA_DEF(a10), \
343 __SHA_DEF(a11), __SHA_DEF(a12)), \
344 __SHA_OPT(a1) "," __SHA_OPT(a2) "," \
345 __SHA_OPT(a3) "," __SHA_OPT(a4) "," \
346 __SHA_OPT(a5) "," __SHA_OPT(a6) "," \
347 __SHA_OPT(a7) "," __SHA_OPT(a8) "," \
348 __SHA_OPT(a9) "," __SHA_OPT(a10) "." \
349 __SHA_OPT(a11) "," __SHA_OPT(a12), \
361 __SHA_TYPEDEF(a10); \
362 __SHA_TYPEDEF(a11); \
363 __SHA_TYPEDEF(a12); \
364 enum {__SHA_ENUM(a1), __SHA_ENUM(a2), __SHA_ENUM(a3), \
365 __SHA_ENUM(a4), __SHA_ENUM(a5), __SHA_ENUM(a6), \
366 __SHA_ENUM(a7), __SHA_ENUM(a8), __SHA_ENUM(a9), \
367 __SHA_ENUM(a10), __SHA_ENUM(a11), __SHA_ENUM(a12)};
369 #define AROS_SHA(type, abbr, name, modf, def) type,abbr,name,modf,def,""
370 #define AROS_SHAH(type, abbr, name, modf, def, help) type,abbr,name,modf,def,"\t" __SHA_OPT(type,abbr,name,modf,def,help) "\t\t" help "\n"
372 #define __AROS_SHA(type, abbr, name, modf, def, help) type,abbr,name,modf,def,help
374 #define AROS_SH12(name, version, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) \
375 __AROS_SH12(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4), __AROS_SHA(a5), __AROS_SHA(a6), __AROS_SHA(a7), __AROS_SHA(a8), __AROS_SHA(a9), __AROS_SHA(a10), __AROS_SHA(a11), __AROS_SHA(a12))
376 #define AROS_SH11(name, version, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
377 __AROS_SH11(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4), __AROS_SHA(a5), __AROS_SHA(a6), __AROS_SHA(a7), __AROS_SHA(a8), __AROS_SHA(a9), __AROS_SHA(a10), __AROS_SHA(a11))
378 #define AROS_SH10(name, version, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)\
379 __AROS_SH10(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4), __AROS_SHA(a5), __AROS_SHA(a6), __AROS_SHA(a7), __AROS_SHA(a8), __AROS_SHA(a9), __AROS_SHA(a10))
380 #define AROS_SH9(name, version, a1, a2, a3, a4, a5, a6, a7, a8, a9) \
381 __AROS_SH9(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4), __AROS_SHA(a5), __AROS_SHA(a6), __AROS_SHA(a7), __AROS_SHA(a8), __AROS_SHA(a9))
382 #define AROS_SH8(name, version, a1, a2, a3, a4, a5, a6, a7, a8) \
383 __AROS_SH8(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4), __AROS_SHA(a5), __AROS_SHA(a6), __AROS_SHA(a7), __AROS_SHA(a8))
384 #define AROS_SH7(name, version, a1, a2, a3, a4, a5, a6, a7) \
385 __AROS_SH7(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4), __AROS_SHA(a5), __AROS_SHA(a6), __AROS_SHA(a7))
386 #define AROS_SH6(name, version, a1, a2, a3, a4, a5, a6) \
387 __AROS_SH6(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4), __AROS_SHA(a5), __AROS_SHA(a6))
388 #define AROS_SH5(name, version, a1, a2, a3, a4, a5) \
389 __AROS_SH5(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4), __AROS_SHA(a5))
390 #define AROS_SH4(name, version, a1, a2, a3, a4) \
391 __AROS_SH4(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3), __AROS_SHA(a4))
392 #define AROS_SH3(name, version, a1, a2, a3) \
393 __AROS_SH3(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2), __AROS_SHA(a3))
394 #define AROS_SH2(name, version, a1, a2) \
395 __AROS_SH2(name, version, "", __AROS_SHA(a1), __AROS_SHA(a2))
396 #define AROS_SH1(name, version, a1) \
397 __AROS_SH1(name, version, "", __AROS_SHA(a1))
398 #define AROS_SH0(name, version) \
399 __AROS_SH0(name, version, "")
401 #define __SH_HELP(name, help) stringify(name) ": " help "\n"
402 #define __SHA_HELP(type, abbr, name, modf, def, help) help
404 #define AROS_SH1H(name, version, help, a1) \
405 __AROS_SH1(name, version, __SH_HELP(name, help) __SHA_HELP(a1), __AROS_SHA(a1))
406 #define AROS_SH0H(name, version, help) \
407 __AROS_SH0(name, version, __SH_HELP(name, help))
409 #endif /* SHCOMMANDS_NOTEMBEDDED_H */