preserve the link register
[AROS.git] / compiler / alib / argarrayinit.c
blobf96efdf04a63cb7223b2366929057b715cc51e69
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*****************************************************************************
8 NAME */
10 #include <exec/types.h>
11 #include <proto/icon.h>
12 #include <proto/dos.h>
13 #include <workbench/workbench.h>
14 #include <workbench/startup.h>
16 extern struct Library *IconBase;
18 /* NOTE: Global variable! */
19 struct DiskObject *__alib_dObject = NULL; /* Used for reading tooltypes */
22 UBYTE **ArgArrayInit(
24 /* SYNOPSIS */
25 ULONG argc,
26 UBYTE **argv )
28 /* FUNCTION
29 Initializes a NULL terminated array of strings that may be passed
30 to icon.library/FindToolType() or the functions ArgInt() and
31 ArgString(). This function can be passed the arguments given to
32 main() regardless of whether the program was called from shell or
33 from workbench.
35 INPUTS
36 argc -- number of arguments to the program when called from shell
37 or 0 if called from workbench
38 argv -- 'argc' pointers to the strings of the arguments; this array
39 should be NULL terminated
41 RESULT
42 A tooltype array to use with FindToolType(); the result of that
43 function can be used with ArgString() and ArgInt() to extract
44 values from the tooltype array. If the process was started from
45 shell the function just returns 'argv'. If no tooltype array could
46 be created, NULL is returned.
48 NOTES
49 This function builds some structures that should be disposed of
50 when the tooltype array is no longer needed. The function
51 ArgArrayDone() does that. This function requires that icon.library
52 has been opened and that IconBase is valid; in fact IconBase must
53 be valid until a call to ArgArrayDone() is made.
55 EXAMPLE
57 BUGS
59 SEE ALSO
60 ArgString(), ArgInt(), ArgArrayDone(), icon.library/FindToolType()
62 INTERNALS
64 HISTORY
65 27.04.98 SDuvan implemented
67 *****************************************************************************/
69 BPTR olddir;
70 struct WBStartup *startup = (struct WBStartup *) argv;
72 if(argc != 0)
73 return argv; /* We were called from shell */
75 if(startup->sm_NumArgs >= 1) /* Paranoia? */
77 olddir = CurrentDir(startup->sm_ArgList[0].wa_Lock);
78 __alib_dObject = GetDiskObject(startup->sm_ArgList[0].wa_Name);
79 CurrentDir(olddir);
81 else
82 return NULL;
84 if(__alib_dObject == NULL)
85 return NULL;
87 return (UBYTE **)__alib_dObject->do_ToolTypes;
88 } /* ArgArrayInit */