OSDN Git Service

Add subsystem specific sysroot mapping facility.
[mingw/mingw-get.git] / src / climain.cpp
1 /*
2  * climain.cpp
3  *
4  * $Id$
5  *
6  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
7  * Copyright (C) 2009, 2010, MinGW Project
8  *
9  *
10  * Implementation of the main program function, which is invoked by
11  * the command line start-up stub when arguments are supplied; this
12  * causes the application to continue running as a CLI process.
13  *
14  *
15  * This is free software.  Permission is granted to copy, modify and
16  * redistribute this software, under the provisions of the GNU General
17  * Public License, Version 3, (or, at your option, any later version),
18  * as published by the Free Software Foundation; see the file COPYING
19  * for licensing details.
20  *
21  * Note, in particular, that this software is provided "as is", in the
22  * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
23  * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
24  * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
25  * MinGW Project, accept liability for any damages, however caused,
26  * arising from the use of this software.
27  *
28  */
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "dmh.h"
33
34 #include "pkgbase.h"
35 #include "pkgtask.h"
36
37 EXTERN_C int climain( int argc, char **argv )
38 {
39   /* Set up the diagnostic message handler, using the console's
40    * `stderr' stream for notifications...
41    */
42   dmh_init( DMH_SUBSYSTEM_TTY, *argv++ );
43
44   /* TODO: insert code here, to interpret any OPTIONS specified
45    * on the command line.
46    */
47
48   /* Interpret the `action keyword', specifying the action to be
49    * performed on this invocation...
50    */
51   int action = action_code( *argv );
52   if( action < 0 )
53     /*
54      * The specified action keyword was invalid;
55      * force an abort through a DMH_FATAL notification...
56      */
57     dmh_notify( DMH_FATAL, "%s: unknown action keyword\n", *argv );
58
59   /* If we get to here, then the specified action identifies a
60    * valid operation; load the package database, according to the
61    * local `profile' configuration, and invoke the operation.
62    */
63   const char *dfile;
64   pkgXmlDocument dbase( dfile = xmlfile( "profile" ) );
65   if( dbase.IsOk() )
66   {
67     /* We successfully loaded the basic settings...
68      * The configuration file name was pushed on to the heap,
69      * by xmlfile(); we don't need that any more, (because it
70      * is reproduced within the database image itself), so
71      * free the heap copy, to avoid memory leaks.
72      */
73     free( (void *)(dfile) );
74
75     /* Merge all package lists, as specified in the "repository"
76      * section of the "profile", into the XML database tree...
77      */
78     if( dbase.BindRepositories( action == ACTION_UPDATE ) == NULL )
79       /*
80        * ...bailing out, on an invalid profile specification...
81        */
82       dmh_notify( DMH_FATAL, "%s: invalid application profile\n", dbase.Value() );
83
84     /* If the requested action was "update", then we've already done it,
85      * as a side effect of binding the cached repository catalogues...
86      */
87     if( action != ACTION_UPDATE )
88     {
89       /* ...otherwise, we need to load the system map...
90        */
91       dbase.LoadSystemMap();
92
93 #if 0
94       /* ...schedule the specified action for each additional command line
95        * argument, (each of which is assumed to represent a package name)...
96        */
97       while( --argc )
98         dbase.Schedule( (unsigned long)(action), *++argv );
99
100       /* ...and finally, execute all scheduled actions.
101        */
102       dbase.ExecuteActions();
103 #endif
104     }
105
106     /* If we get this far, then all actions completed successfully;
107      * we are done.
108      */
109     return EXIT_SUCCESS;
110   }
111
112   /* If we get to here, then the package database load failed;
113    * once more, we force an abort through a DMH_FATAL notification...
114    *
115    * Note: although dmh_notify does not return, in the DMH_FATAL case,
116    * GCC cannot know this, so we pretend that it gives us a return value,
117    * to avoid a possible warning about reaching the end of a non-void
118    * function without a return value assignment...
119    */
120   return dmh_notify( DMH_FATAL, "%s: cannot load configuration\n", dfile );
121 }
122
123 /* $RCSfile$: end of file */