6 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
7 * Copyright (C) 2009, 2010, MinGW Project
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.
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.
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.
37 EXTERN_C int climain( int argc, char **argv )
39 /* Set up the diagnostic message handler, using the console's
40 * `stderr' stream for notifications...
42 dmh_init( DMH_SUBSYSTEM_TTY, *argv++ );
44 /* TODO: insert code here, to interpret any OPTIONS specified
45 * on the command line.
48 /* Interpret the `action keyword', specifying the action to be
49 * performed on this invocation...
51 int action = action_code( *argv );
54 * The specified action keyword was invalid;
55 * force an abort through a DMH_FATAL notification...
57 dmh_notify( DMH_FATAL, "%s: unknown action keyword\n", *argv );
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.
64 pkgXmlDocument dbase( dfile = xmlfile( "profile" ) );
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.
73 free( (void *)(dfile) );
75 /* Merge all package lists, as specified in the "repository"
76 * section of the "profile", into the XML database tree...
78 if( dbase.BindRepositories( action == ACTION_UPDATE ) == NULL )
80 * ...bailing out, on an invalid profile specification...
82 dmh_notify( DMH_FATAL, "%s: invalid application profile\n", dbase.Value() );
84 /* If the requested action was "update", then we've already done it,
85 * as a side effect of binding the cached repository catalogues...
87 if( action != ACTION_UPDATE )
89 /* ...otherwise, we need to load the system map...
91 dbase.LoadSystemMap();
94 /* ...schedule the specified action for each additional command line
95 * argument, (each of which is assumed to represent a package name)...
98 dbase.Schedule( (unsigned long)(action), *++argv );
100 /* ...and finally, execute all scheduled actions.
102 dbase.ExecuteActions();
106 /* If we get this far, then all actions completed successfully;
112 /* If we get to here, then the package database load failed;
113 * once more, we force an abort through a DMH_FATAL notification...
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...
120 return dmh_notify( DMH_FATAL, "%s: cannot load configuration\n", dfile );
123 /* $RCSfile$: end of file */